[英]Search a String excluding html tags in body HTML
If my html is like this 如果我的HTML是这样的
<body>
<b><span>jQuery</span>
is designed to change the way that you write
<span><i>JavaScript</i></span>.</b>
</body>
How can i search for string 我如何搜索字符串
jQuery is designed to change the way that you write JavaScript // This is a Dynamic string
in body html and wrap it with a <span class="we">
tag.. 在正文html中,并用
<span class="we">
标记包装。
Please help me on this.. 请帮助我。
您正在寻找$(htmlString).text()
。
Place this code in the header of your page (making sure you also have the jquery library referenced): 将此代码放在页面标题中(确保您还引用了jquery库):
<script type="text/javascript">
$(function() {
$('b').wrap('<span class="we"/>');
});
</script>
If you need to be more specific, place a class on your b tag so it looks like this 如果需要更具体,请将一个类放在您的b标签上,使其看起来像这样
<script type="text/javascript">
$(function() {
$('b.wrapme').wrap('<span class="we"/>');
});
</script>
<body>
<b class="wrapme"><span>jQuery</span>
is designed to change the way that you write
<span><i>JavaScript</i></span>.</b>
</body>
You can do it by getting innerHTML of element where the text is. 您可以通过获取文本所在元素的innerHTML来实现。 In JavaScript it is:
在JavaScript中,它是:
document.body.innerHTML
$('body').contents().filter(function() {
return $('span', this).length == 2 && $('i', this).length == 1;
}).wrap('<span class="we"></span>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.