jQuery:查找并用某些元素包装文本节点
我的 HTML 代码:
<body>Firebrand will tend to burn any bricks out there. so the best idea is to ignore any active firebrand if you are a bricks. Otherwise, you can challenge a firebrand if you have the proper quality to keep up with their latest technology. And don't mess up with firebrand if you are a robber.</body>
我想找到正文中的任何“firebrand”,并将其替换为 firebrand 和 jQuery
my HTML code :
<body>Firebrand will tend to burn any bricks out there. so the best idea is to ignore any active firebrand if you are a bricks. Otherwise, you can challenge a firebrand if you have the proper quality to keep up with their latest technology. And don't mess up with firebrand if you are a robber.</body>
I want to find any "firebrand" inside the body and replace it with <span class="firebrand">firebrand</span>
with jQuery
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需递归遍历 DOM,同时
使用:
.replace(/(firebrand)/gi, '$1')
。在每个文本内容上
Just recurse through the DOM, while using:
.replace(/(firebrand)/gi, '<span class="firebrand">$1</span>')
on each text content.
尝试以下方法。
Try out the following.