<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>动态给head添加script</title>
<script type="text/javascript">
function addScript(url,inline) {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement('script');
script.type = 'text/javascript';
if (inline) {
script.text = url;
} else {
script.src = url;
}
head.appendChild(script);
}
function test() {
addScript('alert("lanlan");',true);
}
</script>
</head>
<body>
<center>
<input type="button" value="动态给head添加script" οnclick="test()"/>
</center>
</body>
</html>
动态给head添加script
最新推荐文章于 2023-08-11 16:40:22 发布