I doubt the last option, but probably one of the first two. Can anybody tell me which?
I'm getting the error in the screen shot.
<html>
<head>
<script type="text/javascript">
var html = "<script></script>";
</script>
</head>
<body>
</body>
</html>
I doubt the last option, but probably one of the first two. Can anybody tell me which?
I'm getting the error in the screen shot.
<html>
<head>
<script type="text/javascript">
var html = "<script></script>";
</script>
</head>
<body>
</body>
</html>
これはすべてのブラウザで問題になります。スクリプトブロックは最初の文字列で終了する</script>
ため、その文字列がコードのどこかに表示されると、スクリプトブロックが早期に終了します。
これをJSの変数として使用する場合は、次を使用します。
var html = unescape("%3Cscript%3E%3C/script%3E");
\を使用して、その文字を正しくレンダリングすることもできます。
var html = "<script><\/script>";
それはバグではありません。これはスクリプトタグの正しい動作です。実行しているのは、文字列内の引用符をエスケープしないのと同じです。
var string = 'My mother's awesome.';
</script>
問題を修正する簡単な方法は、次のようにタグを分解することです。
var html = "<script></"+"script>";