关于html5的我想两个相加直接输出数值不用点击一下运算
<body><div><form><inputtype="number"size="20"maxlength="5"id="add1"><inputtype="numbe...
<body>
<div>
<form>
<input type="number" size="20" maxlength="5" id ="add1">
<input type="number" size="30" id="add2">
</form>
<button id="btn" onclick="add()">计算</button>
<script>
var i = document.getElementById("add1");
var j = document.getElementById("add2");
function add(){
var sum =i.value + j.value;
document.write(i.value+"+"+ j.value+"="+sum);
}
</script>
</div>
</body> 展开
<div>
<form>
<input type="number" size="20" maxlength="5" id ="add1">
<input type="number" size="30" id="add2">
</form>
<button id="btn" onclick="add()">计算</button>
<script>
var i = document.getElementById("add1");
var j = document.getElementById("add2");
function add(){
var sum =i.value + j.value;
document.write(i.value+"+"+ j.value+"="+sum);
}
</script>
</div>
</body> 展开
2018-01-09
展开全部
<input type="number" size="20" maxlength="5" id ="add1">
<input type="number" size="30" id="add2">
<script>
var i = document.getElementById("add1");
var j = document.getElementById("add2");
function add(){
var sum = parseInt(i.value) + parseInt(j.value);
document.write(sum);
}
document.getElementById("add1").onchange = function () {
document.getElementById("add2").onchange = function () {
add();
}
}
document.getElementById("add2").onchange = function () {
document.getElementById("add1").onchange = function () {
add();
}
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询