首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

简单计算机的编写,该怎么解决

2012-05-21 
简单计算机的编写bodyform idform1 nameform1 methodpost actionlabelinput typetex

简单计算机的编写

<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> 

热点排行