1 回答

慕码人2483693
TA贡献1860条经验 获得超9个赞
可以的,需要把 </script>改为 <\/script>;例如:
<html>
<head>
<script type="text/javascript">
function createNewDoc()
{
var txts="";
var newDoc=document.open("text/html","replace");
var txt="<html><body>Learning about the DOM is FUN!\
<input type='button' value='dynamic response'/> \
<script> function warning(){ alert(\"new document\");}\
document.getElementsByTagName('input')[0].addEventListener('click',warning);\
<\/script><\/body><\/html>";
console.log(txt);
newDoc.write(txt);
newDoc.close();
}
</script>
<body>
<input type="button" value="Write to a new document"
onclick="createNewDoc()">
</body>
</html>
添加回答
举报
0/150
提交
取消