<body> | |
请输入第一个数<input type="text" id="first"><br /><br /> | |
请输入第二个数<input type="text" id="second"><br /><br /> | |
计算结果<input type="text" id="get_result"> | |
<!--计算结果<p id="result" ></p>--> | |
<input type="button" value="+" id="add" onclick="check('+');"> | |
<input type="button" value="-" id="jian" onclick="check('-');"> | |
<input type="button" value="*" id="cheng" onclick="check('*');"> | |
<input type="button" value="/" id="chu" onchange="check('/');"><br /><br /> | |
<!--<input type="button" value="计算" οnclick="jisuan();">--> | |
<script> | |
var c=0; | |
function check(obj){ | |
var a=parseInt(document.getElementById("first").value); | |
var b=parseInt(document.getElementById("second").value); | |
if(obj=='+'){ | |
// alert("b"); | |
c=parseInt(a)+parseInt(b); | |
} | |
if(obj=='-'){ | |
c=parseInt(a)-parseInt(b); | |
} | |
if(obj=='*'){ | |
c=parseInt(a)*parseInt(b); | |
} | |
if(obj=='/'){ | |
c=parseInt(a)/parseInt(b); | |
} | |
var res = document.getElementById("get_result"); // 这里我刚开始的时候直接写的 .value ,但是不行,感觉是 a=b,b=c 但是a不等于c的原因 | |
res.value = c; | |
} | |
</script> | |
</body> |
如何改变
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.