Jquery中替换节点的方法replaceWith()和replaceAll()
来源:互联网 发布:网络美工是做什么的 编辑:程序博客网 时间:2024/05/01 14:03
在jquery中,我们可以通过replaceWith()和replaceAll()方法来替换元素中的节点。
语法格式:replaceWith(content) 将所有选择的元素替换成指定的html和dom元素。其中参数被选择替换的内容。
replaceAll(selector) 替换指定的selector元素。
示例:在下面的页面中存在两个span标记。通过上面两个函数分别替换元素的内容
1 <script type="text/javascript">
2 $(function() {
3 $("#Span1").replaceWith("<span title='replaceWith'>Rainier</span>");
4 $("<span title='replaceAll'>han163@163.com</span>").replaceAll("#Span2");
5 })
6 </script>
7 </head>
8 <body>
9 <p>姓名:<span id="Span1"></span></p>
10 <p>邮箱:<span id="Span2"></span></p>
11 </body>
2 $(function() {
3 $("#Span1").replaceWith("<span title='replaceWith'>Rainier</span>");
4 $("<span title='replaceAll'>han163@163.com</span>").replaceAll("#Span2");
5 })
6 </script>
7 </head>
8 <body>
9 <p>姓名:<span id="Span1"></span></p>
10 <p>邮箱:<span id="Span2"></span></p>
11 </body>
注意 replaceWith() 与replaceAll() 方法都可以实现元素节点的替换,二者最大的区别在
于替换字符的顺序,前者是用括号中的字符替换所选择的元素,后者是用字符串替换括号中
所选择的元素。同时,一旦完成替换,被替换元素中的全部事件都将消失。
1 0
- Jquery中替换节点的方法replaceWith()和replaceAll()
- Jquery中替换节点的方法replaceWith()和replaceAll()
- jquery 替换节点 replaceWith(), 和replaceAll( )
- DOM替换replaceWith()和replaceAll() 之前学习了节点的内插入、外插入以及删除方法,这节会学习替换方法replaceWith .replaceWith( newConten
- 【JQuery】replaceWith()和replaceAll()替换内容
- Jquery的替换(replaceWith())
- 【jQuery】replaceWith()和replaceAll()
- DOM替换replaceWith()和replaceAll()
- DOM替换replaceWith()和replaceAll()
- replaceWith()和replaceAll() 和html()
- JQuery中replaceWith(content),replaceAll(selector)
- jquery replaceWith replaceAll
- jquery删除替换元素remove、detach、empty、replaceWith、replaceAll
- replace,replaceAll,replaceWith的区别
- replace和replaceAll是JAVA中常用的替换字符的方法(转载)
- replace和replaceAll是JAVA中常用的替换字符的方法
- replace和replaceAll是JAVA中常用的替换字符的方法
- javascript中使用replaceAll()函数实现字符替换的方法
- webserver日志中\xCF\xE3\xB8\xDB\xCA\xAE\xB4\xF3\xCE\xC4\xBB\xAF\xB7\xFB\xBA\xC5这种形式原因及处理
- 将jpeg图片显示在framebuffer上
- SGU 176Flow construction 有源汇上下界网络流 最小流
- Maven多工程依赖在Eclipse中发布到Server被依赖工程没有生成jar的问题
- Unity——MVC(很不错的解释应用)
- Jquery中替换节点的方法replaceWith()和replaceAll()
- FRAMEBUFFER 显示原理及RGB显示
- 衡阳哪个微信公众号最好?
- JavaScript基础回顾
- 机器学习实战2:k近邻算法KNN(python)
- 【NOIP2013-D1T3】货车运输
- 基于Netty的RPC简单框架实现(二):RPC服务端
- 63行代码实现贪吃蛇
- synchronized 与 lock