<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style></style>
</head>
<body>
<h1>Head</h1>
<script>
document.write('<script>alert(123) <\/script>'); //这里同理是让js解析的时候再识别括号里面的script标签,这样就避免了括号里面的script标签和最上的的script标签形成一对引起的错误
var txt = "We are the so-called \"Vikings\" from the north."
var txt2 = "We are the so-called "Vikings" from the north."
document.write(txt); //We are the so-called "Vikings" from the north.
document.write(txt2); //We are the so-called "Vikings" from the north.
console.log(txt); //We are the so-called "Vikings" from the north. \是被js转义,不被浏览器转义
console.log(txt2); //We are the so-called "Vikings" from the north. "被浏览器转义,不被js转义
</script>
<h2>Tail</h2>
</body>
</html>
js中\转义符
最新推荐文章于 2023-11-03 10:11:19 发布