[英]getElementsByTagName exclude script tag
As the title suggests I want to exclude the script tag. 如标题所示,我想排除脚本标签。
Cause while using regex (at least I think that's the right name :P) 原因在使用正则表达式时(至少我认为这是正确的名称:P)
I get to a point where something 我到了某个地方
var wdc = /something/g;
is included inside the 包含在
var foundwdc = words.match(wdc).length;
So when I alert foundwdc it gives 3 "somethings" instead of the desired two inside the body 因此,当我提醒foundwdc时,它会给出3个“东西”,而不是体内所需的两个东西
var words = document.getElementsByTagName('body')[0].innerHTML;
Hope this is clear enough :D and hope the title is right :P 希望这是足够清晰的:D并希望标题是正确的:P
Use replace()
to remove the script tag from string 使用
replace()
从字符串中删除脚本标签
var words = document.getElementsByTagName('body')[0].innerHTML.replace(/<script[^>]*>[\\s\\S]*?<\\/script>/gi, ''); console.log(words);
hi hello <script> </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.