背景
html文档解析的时候,是自上而下解析的,如果碰到了script标签,则会进行下载并执行了
如果这个时候,我们的内嵌script标签里面有类似’’标签的字眼,会怎么样呢??
如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>test</title>
</head>
<body>
<h1>哈哈哈</h1>
<script>
function fn() {
console.log('</script>')
}
fn()
</script>
</body>
</html>
运行页面发生如下情况:
同时控制台报错:test.html:20 Uncaught SyntaxError: Invalid or unexpected token
日常开发的时候可能无法遇到这种情况,但是了解一下总是没问题的哈