本文介绍了jquery中有任何文本选择器吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jquery中是否有文本选择器?
Are there any text selector in jquery ?
我的代码
<anything>Hello World! Hello World!</anything>Reslut应该是(使用Jquery)
Reslut Should be (Using Jquery)
<anything>Hello <span>World</span>! Hello <span>World</span>!</anything>推荐答案
$('anything').html(function(i, v) { return v.replace(/(World)/g, '<span>$1</span>'); });
上面的代码片段使用jQuery 1.4中添加的功能。
The above snippet uses functionality added in jQuery 1.4.
注意: 此解决方案对于仅包含原始文本(且没有子元素)的元素是安全的。
Note: this solution is safe for elements containing only raw text (and no child elements).
更多推荐
jquery中有任何文本选择器吗?
发布评论