replaceAll(selector)方法将指定选择器匹配的元素替换为匹配的元素。
selector.replaceAll( selector )
下面是此方法使用的所有参数的说明
selector - 要查找并替换匹配元素的元素。
下面是一个简单的示例,一个简单的示例说明了该方法的用法。这将用新的除法-替换单击的一个正方形
<html> <head> <title>The jQuery Example</title> <script type = "text/javascript" src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type = "text/javascript" language = "javascript"> $(document).ready(function() { $("div").click(function () { $('<div class="div"></div>').replaceAll( this ); }); }); </script> <style> .div{ margin:10px;padding:12px; border:2px solid #666; width:60px;} </style> </head> <body> <p>Click on any square below to see the result:</p> <div class = "div" style = "background-color:blue;">ONE</div> <div class = "div" style = "background-color:green;">TWO</div> <div class = "div" style = "background-color:red;">THREE</div> </body> </html>
这将产生以下输出-
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Tony Bai · Go语言第一课 -〔Tony Bai〕