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

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());
});
posted @ 2015-05-28 16:56  KenmuHuang  阅读(337)  评论(0编辑  收藏  举报
如果您看完本篇博文,觉得对您有所收获,请点击右下角的 [推荐]
如果您想转载,请注明出处(原创内容,请尊重个人劳动成果)
如果您有任何意见或建议,欢迎留言
感谢您的阅读,敬请关注我的后续博客文章