我是编程新手。我试图建立一个程序,所以当用户向表单中提交2个整数时,它会输出总和。从html表单到javascript变量
这里是我到目前为止
<html>
<h1> The Adder </h1>
<form>
Enter your first number<input type="text" id='a'> <br>
Enter your second number<input type="text"id='b' <br>
<input type= "button" onclick='add()' value="Submit"/>
</form>
<script>
function add(){
var avalue= document.getElementById('a');
var bvalue= document.getElementById('b');
alert(avalue+bvalue);
}
</script>
</html>
您应该使用:VAR安勤=的document.getElementById( 'A')VA略; AND var bvalue = document.getElementById('b')。value; –