<body>
<form id="form1" name="form1" method="post" action="">
<label>
<input type="text" name="text1" id="text1"/>
<select name="select" id="select">
<option value="add">+</option>
<option value="minus">-</option>
<option value="multiply">*</option>
<option value="divide">/</option></select>
<input type="text" name="text2" id="text2"/>
<input name="equel" type="button" id="equel" onclick="count()" value="="/>
<input type="text" name="text3" id="text3"/>
</label>
</form>
</body>
</html>
<script language="javascript">
function count()
{
var text1 = document.getElementById("text1");
var text2 = document.getElementById("text2");
var text3 = document.getElementById("text3");
var mark = document.getElementById("select").value;
if(mark == "add")
text3 = parseInt(text1) + parseInt(text2) ;
if(mark == "minus")
text3 = parseInt(text1) - parseInt(text2) ;
if(mark == "multiply")
text3 = parseInt(text1) * parseInt(text2) ;
if(mark == "divide")
text3 = parseInt(text1) / parseInt(text2) ;
}
</script>
大家帮忙看下为什么那个调用“count()”这个函数没有反应呢
------解决方案--------------------
text3.value = ...
------解决方案--------------------
text1 = document.getElementById("text1").value;
text3.value = ...
------解决方案--------------------
- HTML code
<html> <head> </head> <body> <form id="form1" name="form1" method="post" action=""> <input type="text" name="text1" id="text1"/> <select name="select" id="select"> <option value="add">+</option> <option value="minus">-</option> <option value="multiply">*</option> <option value="divide">/</option></select> <input type="text" name="text2" id="text2"/> <input name="equel" type="button" id="equel" onclick="count()" value="="/> <input type="text" name="text3" id="text3"/> </form> </body> </html> <script language="javascript"> function count() { var text1 = document.getElementById("text1").value; var text2 = document.getElementById("text2").value; var text3 = document.getElementById("text3"); var mark = document.getElementById("select").value; if(mark == "add") text3.value = parseInt(text1) + parseInt(text2) ; if(mark == "minus") text3.value = parseInt(text1) - parseInt(text2) ; if(mark == "multiply") text3.value= parseInt(text1) * parseInt(text2) ; if(mark == "divide") text3.value= parseInt(text1) / parseInt(text2) ; } </script> </body> <html>