[英]replace all </script> tags with <\/script> in javascript or jquery
I need to replace all these tags </script>
with these tags </script>
我需要用这些标记
</script>
替换所有这些标记</script>
Before: -> <script>..code..</script> <script>..code..</script>
之前: - >
<script>..code..</script> <script>..code..</script>
After: ---> <script>..code..<\\/script> <script>..code..<\\/script>
之后:--->
<script>..code..<\\/script> <script>..code..<\\/script>
But this does not work: 但这不起作用:
function myReplace(){
var X = document.getElementById("demo").innerText;
var Y = X.replace(/</script>/ig, '<\/script>');
document.getElementById("demo").innerText = Y;
}
Here's a related post for a better understanding
这是一篇相关文章,以便更好地理解
It looks like your expression isn't going to work. 看起来你的表达不起作用。 Your slashes aren't being escaped properly.
你的斜杠没有正确转义。 Try this.
尝试这个。
function myReplace(){
var X = document.getElementById("demo").innerHTML;
var Y = X.replace(/<\/script>/ig, "<\\\/script>");
document.getElementById("demo").innerText = Y;
}
I also found a good article about how to do this and why. 我还找到了一篇关于如何做到这一点及其原因的好文章 。 They go to the extent of escaping your < and > sign's, but I believe escaping your your forward slashes is the most important.
它们会逃避你的<和>符号,但我相信逃避你的正斜线是最重要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.