<div class="row">
<div class="col-xs-12" id="sumall"></div>
</div>
<form role="form">
<div class="form-group">
<input class="form-control" type="text" name="num1">
<input class="form-control" type="text" name="num2">
<input class="form-control" type="text" name="num3">
<input type="submit" onclick = "sumAll(num1,num2,num3)" value="OK">
</div>
我是一个总菜鸟!
尝试将数字从3个输入字段传递给函数但没有得到响应。控制台显示没有错误,警告语句显示[object HTMLInputElement]?那么它返回对象而不是值?
请帮帮我???
function sumAll(num1,num2,num3) {
alert(num1);
var sum = num1 + num2 + num3;
document.getElementById("sumall").innerHTML = "<p>" + "The number is: " + sum + "</p>";
return;
}
答案 0 :(得分:0)
你需要在num1 2 3上调用#map {
pointer-events: none;
}
来获得结果。
.value
&#13;
function sumAll(num1,num2,num3) {
var sum = Number(num1.value) + Number(num2.value) + Number(num3.value);
alert(sum);
}
&#13;