为什么逃避/在javascript'< \ / script>'? [英] why escaping / in javascript '<\/script>'?
本文介绍了为什么逃避/在javascript'< \ / script>'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我看到每个人都在这样做,我不明白为什么。
I have seen everyone doing it tho i dont' get why.
document.write('<script src="src"><\/script>');
我的意思是使用单身'你不需要esacape chars?
I mean using the single ' you shouldn't need to esacape chars?
推荐答案
- 单引号和双引号字符串具有相同的转义规则。
- 它可以防止
< / script>
被解析为结束标记。
- Single and double quoted strings have the same escaping rules.
- It prevents
</script>
from being parsed as an closing tag.
< / script>
和< \ / script>
与 JavaScript <相同/ em>,但只有第一个由 HTML 解析器解释为包含HTML结束标记。
"</script>
and "<\/script>
" are the same to JavaScript, but only the first one is interpreted by the HTML parser to contain a HTML closing tag.
这篇关于为什么逃避/在javascript'< \ / script>'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文