当前位置: 代码迷 >> JavaScript >> 请帮忙解释一下代码,小弟我看不懂
  详细解决方案

请帮忙解释一下代码,小弟我看不懂

热度:133   发布时间:2012-03-03 15:33:03.0
请帮忙解释一下代码,我看不懂
主要就是有颜色的句子不明白,请帮忙看下,谢谢了


<head>
  <title>A simple calculator</title>
   
  <script type = "text/javascript">
  <!--

  function doit() {
  form.input.value = eval(form.input.value)
  }


   
  </script>
   
  </head>

  <body>
  <form name = "form" action = "">
   
  <table border = "1" width = "450" cellspacing = "5"
  summary = "This is a calculator used to calculate simple mathematics operations">

  <caption>Simple Calculator</caption>

  <thead></thead>
   
   
  <tbody>
  <tr>
  <td colspan = "3" height = "15">
  <input name = "input" type = "text" size = "32"></td>
  </tr>

  <tr>
  <td width = "60" height = "15">
  <input name = "one" type = "button" value = " 1 "
  onClick = "form.input.value += '1'" /></td>
  <td width = "60" height = "15">
  <input name = "two" type = "button" value = " 2 "
  onClick = "form.input.value += '2'" /></td>
  <td width = "60" height = "15">
  <input name = "three" type = "button" value = " 3 "
  onClick = "form.input.value += '3'" /></td>
  <td width = "1" height = "15"></td>
  <td width = "60" height = "15">
  <input name = "MultiplySign" type = "button" value = " * "
  onClick = "form.input.value += '*'" /></td>  
  </tr>
   

  <tr>
  <td width = "60" height = "15"> 
  <input name = "equal" type = "button" value = " = "
  onClick = "doit()" /></td>  
  </tr>  
   
  </table>
  </form> 
  </body>



------解决方案--------------------
form.input.value += '1'
相当于在form.input.value = form.input.value + '1'
意思是在原来的基础上加1
------解决方案--------------------
将原先的value后追加(1,2,3,*)
。。。。
------解决方案--------------------
这个form.input.value 指的是这个 <input name = "input" type = "text" size = "32">的value,

按钮的value值只是做显示用,显示在按钮的表面,

当然他的功能,就是onClick里面执行的,把上面那个input的值改变。
------解决方案--------------------