
获得徽章 7
赞了这篇文章
赞了这篇沸点
前端扫盲系列:
juejin.cn
你不知道的动态脚本 —— 以下两段代码有什么区别?为什么?
<!DOCTYPE html>
<html lang="en">
<body>
<script>
document.body.innerHTML = "\<script\>function test() { alert('你在弄啥嘞??') };\<\/script>"
test()
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<body>
<script>
const script = document.createElement('script')
const content = document.createTextNode('function test() { alert("瞅啥??") }')
script.appendChild(content)
document.body.appendChild(script)
test()
</script>
</body>
</html>
你不知道的动态脚本 —— 以下两段代码有什么区别?为什么?
<!DOCTYPE html>
<html lang="en">
<body>
<script>
document.body.innerHTML = "\<script\>function test() { alert('你在弄啥嘞??') };\<\/script>"
test()
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<body>
<script>
const script = document.createElement('script')
const content = document.createTextNode('function test() { alert("瞅啥??") }')
script.appendChild(content)
document.body.appendChild(script)
test()
</script>
</body>
</html>
展开
1
13
赞了这篇文章
赞了这篇文章
赞了这篇沸点
赞了这篇文章
赞了这篇文章
赞了这篇文章