Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery检查字符串周围是否有span标记? var text='word otherword theotherword';_Jquery_Html_Css - Fatal编程技术网

使用jQuery检查字符串周围是否有span标记? var text='word otherword theotherword';

使用jQuery检查字符串周围是否有span标记? var text='word otherword theotherword';,jquery,html,css,Jquery,Html,Css,我将迭代文本的所有字符,并检查字符周围是否有span标记。在本例中,o-t-h-e-r-w-o-r-d字符具有span标记。如何检查字符周围是否存在span标记 我的意思是:我想通过迭代来检查文本中的所有字符,看看它所属的单词周围是否有span标记。因为我需要将字符替换为除包含span元素的单词中的字符之外的其他字符 var text='word <span>otherword</span> theotherword'; otherword。。。 我需要将字符替换为具

我将迭代文本的所有字符,并检查字符周围是否有span标记。在本例中,o-t-h-e-r-w-o-r-d字符具有span标记。如何检查字符周围是否存在span标记

我的意思是:我想通过迭代来检查文本中的所有字符,看看它所属的单词周围是否有span标记。因为我需要将字符替换为除包含span元素的单词中的字符之外的其他字符

var text='word <span>otherword</span> theotherword';
otherword。。。
我需要将字符替换为具有span元素的单词中的字符除外

您可以简单地使用正则表达式:

&nbsp;&nbsp;&nbsp; <span>otherword</span> &nbsp;&nbsp;&nbsp;...
$(文档).ready(函数(){
如果($(“p:contains(in)”){
$(“p”).text()替换(“,”);
$(“p”).text()替换(“,”);
}
});


word otherword theotherword

使用
$(text).filter('span').length
但我想通过迭代检查所有字符,看看它所属的单词周围是否有span标记。如果坚持这样做,就不能使用jQuery。告诉我们你为什么要这么做?也许有一种更简单的方法来完成您想要做的事情,一旦您知道某些文本周围有一个span?您可以使用regex而不是迭代字符串,并在您的案例中找到模式
sometext
,这将有所帮助。我需要将字符替换为除单词中具有span元素的字符以外的字符。OP的默认字符串不包含
var text='word otherword theotherword'这不符合@tablex的要求。
<span>.*&nbsp;.*</span>