>  기사  >  웹 프론트엔드  >  HTML과 JS는 간단한 계산기를 구현합니다.

HTML과 JS는 간단한 계산기를 구현합니다.

小云云
小云云원래의
2018-03-05 15:09:342018검색

HTML과 JS에서 계산기 기능을 구현하는 것도 매우 쉽습니다. 이 글에서는 HTML과 JS에서 간단한 계산기를 구현하는 방법을 주로 공유하겠습니다.

다음 코드는 다음과 같습니다.

   <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="untitled.css">
</head>
<script type="text/javascript"> 
        var result="";
          function jisuan(num){
      if(num=="="){
  document.form1.text.value=eval(result);
  }else{
  result=result+num;
  document.form1.text.value=result;
  }
  }
</script>
<body>
<p class="box">
<form action="" class="form1" name="form1">
      <p class="header"> 
         <input type="text" id="text" name="text" class="text"/>
        
          </p>
          <p class="nav">
     <table class="table">
         <tr>
         <td>  <input id="1" style="height:55px; width:55px;" type="button" value="1" onClick="jisuan(this.id)"/> </td>
         <td>  <input id="2" style="height:55px; width:55px;" type="button" value="2" onClick="jisuan(this.id)"/> </td>
         <td>  <input id="3" style="height:55px; width:55px;" type="button" value="3" onClick="jisuan(this.id)"/> </td>
         <td>  <input id="+" style="height:55px; width:55px;" type="button" value="+" onClick="jisuan(this.id)"/> </td>
         </tr>
         <tr>
         <td>  <input id="4" style="height:55px; width:55px;" type="button" value="4" onClick="jisuan(this.id)"/> </td>
         <td>  <input id="5" style="height:55px; width:55px;" type="button" value="5" onClick="jisuan(this.id)"/> </td>
         <td>  <input id="6" style="height:55px; width:55px;" type="button" value="6" onClick="jisuan(this.id)"/> </td>
          <td>  <input id="-" style="height:55px; width:55px;" type="button" value="-" onClick="jisuan(this.id)"/> </td>
         </tr>
         <tr>
         <td>  <input id="7" style="height:55px; width:55px;" type="button" value="7" onClick="jisuan(this.id)"/> </td>
         <td>  <input id="8" style="height:55px; width:55px;" type="button" value="8" onClick="jisuan(this.id)"/> </td>
         <td>  <input id="9" style="height:55px; width:55px;" type="button" value="9" onClick="jisuan(this.id)"/> </td>
          <td>  <input id="*" style="height:55px; width:55px;" type="button" value="*" onClick="jisuan(this.id)"/> </td>
         </tr>
          <tr>
         <td>  <input id="/" style="height:55px; width:55px;" type="button" value="/" onClick="jisuan(this.id)"/> </td>
         <td>  <input id="0" style="height:55px; width:55px;" type="button" value="0" onClick="jisuan(this.id)"/> </td>
          <td>  <input id="." style="height:55px; width:55px;" type="button" value="." onClick="jisuan(this.id)"/></td>
          <td>  <input id="=" style="height:55px; width:55px;" type="button" value="=" onClick="jisuan(this.id)"/> </td>
         </tr>
         </table>
        
         
     </p>
   </form>
 </p>
</body>
</html>

관련 권장 사항:
간단한 4가지 산술 연산 계산기 기능을 구현하기 위해 HTML

js에서 간단한 계산기를 구현하는 방법

JS에서 간단한 4가지 산술 연산을 구현하는 방법 계산기 기능 예시

위 내용은 HTML과 JS는 간단한 계산기를 구현합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.