js寫的計算器

  <!DOCTYPE html>
  <HTML>
  <HEAD>
  <TITLE>作業第三題</ TITLE>
  </ HEAD>
  <style type =“text / css”>
  輸入{width:100px; height:20px; margin-left:20px; margin-top:10px;}
  .operator {width:25px; height:25px; text-align:center; line-height:25px;}
  </樣式>
  <BODY>
  <input type =“text”id =“firstnumb”placeholder =“firstnumb”>
  <input type =“text”id =“secondnumb”placeholder =“secondnumb”>
  &NBSP;&NBSP; =
  <input type =“text”id =“result”name =“result”placeholder =“result”>
  點擊
  <input type =“button”class =“operator”value ='加'>
  <input type =“button”class =“operator”value ='減'
  <input type =“button”class =“operator”value ='乘'>
  <input type =“button”class =“operator”value ='除'>
  </ BODY>
  <script type =“text / javascript”>
  var ofirst = document.getElementById('firstnumb');
  var osecond = document.getElementById('secondnumb');
  var oresult = document.getElementById('result');
  var oboperator = document.getElementsByClassName('operator');
  oboperator [0] = .onclick函數(){
  oresult.value = parseFloat(ofirst.value)+ parseFloat(osecond.value)
  };
  oboperator [1] .onclick =函數(){
  oresult.value = parseFloat(ofirst.value)-parseFloat(osecond.value)
  };
  oboperator [2] = .onclick函數(){
  oresult.value = parseFloat(ofirst.value)* parseFloat(osecond.value)
  };
  oboperator [3] = .onclick函數(){
  oresult.value = parseFloat(ofirst.value)/ parseFloat(osecond.value)
  };
  </ SCRIPT>
  </ HTML>
   
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章