jquery中有任何文本选择器吗?

编程入门 行业动态 更新时间:2024-10-27 20:34:31
本文介绍了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中有任何文本选择器吗?

本文发布于:2023-10-23 04:19:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519761.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中有   文本   选择器   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!