gpt4 book ai didi

JavaScript 不工作

转载 作者:行者123 更新时间:2023-11-28 16:36:55 25 4
gpt4 key购买 nike

我有一个 JavaScript 函数,我将在这个函数中编写

<script type='text/JavaScript' language='JavaScript'>alert('ha')</script>

但是在执行此页面时它不起作用。这是我的代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<script language="javascript" type="text/javascript">
function asd()
{
document.write("<script language='javascript' type='text/javascript'>alert('asdasd');</" + "script>");
}
</script>
</head>
<body onload="asd();">
<span id="gdfg"></span>
<span>dgdfghfghfghfg</span>
</body>
</html>

最佳答案

拉斐尔的意思是这个

window.onload=function() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '/myalert.js';
document.getElementsByTagName("head")[0].appendChild(script);
}

window.onload=function() {
var script = document.createElement('script');
script.type = 'text/javascript';
var textNode = document.createTextNode('alert("bla");')
script.appendChild(textNode)';
document.getElementsByTagName("head")[0].appendChild(script);
}

关于JavaScript 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3504718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com