gangsterJ4229053
2016-12-16 10:47
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
var i=Math.random()*10;
document.getElementsByTagName("button")[0].onclick=function(){
document.getElementsByTagName("button")[0].innerHTML=round(i)
}
</script>
</head>
<body>
<button>点击</button>
</body>
</html>
为什么点击没有变化呢
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Math </title>
<script type="text/javascript">
function func_click()
{
var i=Math.random()*10;
var myobj = document.getElementsByTagName("button")[0];
//var myobj = document.getElementById("button");
myobj.innerHTML = i;
document.write(myobj.innerHTML);
}
</script>
</head>
<body>
<button id="button" onclick="func_click()">点击</button>
</body>
</html>
If I were you I will split such function into sortable steps...
button不是名字
<button id="xxxx" name="xxxx" class="xxxx">点击</button>
document.getElementsByTagName("xxxx")[0].onclick=function(){
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题