为了账号安全,请及时绑定邮箱和手机立即绑定

上代码,自己看去

<!DOCTYPE html>
<html>
 <head>
  <title> 事件</title>  
  <script type="text/javascript">
   window.onload =  function() {
      document.getElementsByTagName('input')[2].onclick = 
      function() {
         var t1 = document.getElementsByTagName('input')[0].value;
         var t2 = document.getElementsByTagName('input')[1].value;
         if(!isNaN(parseInt(t1)) && !isNaN(parseInt(t2))) {
            document.getElementsByTagName('input')[3].value  =  parseInt(t1) + parseInt(t2);             
         } else {
             alert("请填写正确的数字");
         }
      }
   }
  </script> 
 </head> 
 <body>
   <input type='text' id='txt1' /> 
   <select id='select'>
		<option value='+'>+</option>
		<option value="-">-</option>
		<option value="*">*</option>
		<option value="/">/</option>
   </select>
   <input type='text' id='txt2' /> 
   <input type='button' value=' = ' /> <!--通过 = 按钮来调用创建的函数,得到结果--> 
   <input type='text' id='fruit' />   
 </body>
</html>


正在回答

2 回答

举报

0/150
提交
取消

上代码,自己看去

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信