首页 > Web开发 > 详细

避免使用jQuery的html方法来替换标签,而是使用replaceWith方法

时间:2015-05-28 17:33:04      阅读:1394      评论:0      收藏:0      [点我收藏+]
tblCostSplit.html内容:
<nobr title="">只想显示里面内容,去掉nobr标签</nobr>
<nobr title="">只想显示里面内容,去掉nobr标签</nobr>
<nobr title="">只想显示里面内容,去掉nobr标签</nobr>
 
(1)html方法,会导致原来Dom内容的绑定事件出现错误,不建议使用
tblCostSplit.html(tblCostSplit.html().replace(/<nobr.*?>/ig"").replace(/<\/nobr>/ig""));  
 
(2)replaceWith方法,能正常替代标签,建议使用
jQuery("nobr", tblCostSplit).each(function () {
    jQuery(this).replaceWith(jQuery(this).html());
});

避免使用jQuery的html方法来替换标签,而是使用replaceWith方法

原文:http://www.cnblogs.com/huangjianwu/p/4536358.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!