Detonate
2015-09-25 10:49
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script type="text/javascript">
var main = document.body;
var p1 = document.createElement("p");
var p2 = document.createElement("p");
var br = document.createElement("br");
var inp1 = document.createElement("input");
var inp2 = document.createElement("input");
var inp3 = document.createElement("input");
p1.innerHTML = "高度:";
p2.innerHTML = "宽度:";
inp1.type = "text";
inp2.type = "text";
inp3.type = "button";
inp3.value = "显示可视区域大小";
main.appendChild(p1);
main.appendChild(inp1);
main.appendChild(p2);
main.appendChild(inp2);
main.appendChild(br);
main.appendChild(inp3);
inp3.setAttribute("onclick",test())
function test(){
alert("test!")
}
/*function getv(){
var w =document.documentElement.clientWidth||document.body.clientHeight;
var h = document.documentElement.clientHeight||document.body.clientHeight;
inp1.value = w;
inp2.value = h;
//document.write(w)
}*/
</script>
</body>
</html>
inp3.setAttribute("onclick","test()");
代码改成这样就可以了。
JavaScript进阶篇
468800 学习 · 22582 问题
相似问题