如题;只要点击那个按钮就报错。说是seme没有定义之类的。。。请大神帮解答解答;我错在哪里。
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
window.onload = function sume(){
var i=10;
var j=10;
var m=j+i;
document.getElementById("pci1").innerHTML=m;
};
</script>
</head>
<body>
<div id="pci1">世界,你好</div>
<div>i=10;j=10;m=?</div>
<input type="button" value="结果" onclick="sume()" />
</body>
</html>
因为没有声明这个函数或者说变量,它只是赋值给了window.onload,并没有声明,所以其他地方不能调用没有声明过得函数,从底层上看这个线程的栈中没有这个变量的引用,正确的方法应该是function sume(),再赋值给window.onload。