注册 登录
编程论坛 JavaScript论坛

无解,这段代码为什么无法运行?

weifeng378 发布于 2016-12-31 22:56, 3356 次点击
程序代码:
求,和的代码/???
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>I love Chen.....</title>
<script>
window.onload=function(){
    var oTxt1 = document.getElementById("txt1");
    var oTxt2 = document.getElementById("btn2");
    var oBtn = document.getElementById("btn1");
    oBtn.onclick = function(){
        alert(parseInt(oTxt1.value) + parseInt(oTxt2.value));
    };
  
};


</script>
</head>
<body>
<input type="text" id="txt1" />
<input type="text" id="txt2" />
<input type="button" id="btn1" value="求和" />
</body>
</html>
7 回复
#2
weifeng3782016-12-31 23:01
计算不了结果....
#3
leeqihero2017-01-03 09:55
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<input type="text" id=1 />
<input type="text" id=2 />
<input type="button" id=3 value="求和" />
</body>
<script>
var a=document.getElementById(1);
var b=document.getElementById(2);
var c=document.getElementById(3);
c.onclick=function(){
    alert(a.value*1+b.value*1);
}
</script>
</html>
#4
曹大双2017-01-09 15:47
btn2???
#5
liujh132017-09-01 12:05
自己改下
var oTxt1 = document.getElementById("txt1");
 var oTxt2 = document.getElementById("txt2");
   
#6
小青3452017-09-03 09:30
看不懂
#7
qq168coh2017-09-29 01:39
哪来的btn2?
#8
leeqihero2018-03-15 16:49
<html>
<head>
<meta charset=utf-8>
</head>
<body>
<input type=text id=1 />
<input type=text id=2 />
<input type=button id=3 value=求和 />
</body>
<script>
$=function(b){return document.getElementById(b)};
$(3).onclick=function(){
    alert(eval($(1).value+'+'+$(2).value));
  
};
</script>
</html>
1