Home > Web Front-end > JS Tutorial > JS implements simple four arithmetic operations

JS implements simple four arithmetic operations

php中世界最好的语言
Release: 2018-04-19 11:31:13
Original
4130 people have browsed it

This time I will bring you JSimplementation of simple four arithmetic operations, JS implementation of simple four arithmetic operationsWhat are the precautions, the following are Let’s take a look at practical cases.

The specific code is as follows:

<table class="tab">
    <tbody>
        <tr class="tr2">   
            <td colspan="4">
                简易计算器
            </td>
        </tr> 
        <tr class="tr">             
            <td id="result" colspan="4">                
            </td> 
        </tr> 
        <tr>             
            <td id="+" class="tr1">
                +
            </td> 
            <td id="-" class="tr1">
                -
            </td> 
            <td id="*" class="tr1">
                *
            </td> 
            <td id="/" class="tr1">
                /
            </td> 
        </tr> 
        <tr>            
            <td id="7" class="tr1">
                7
            </td>
            <td id="8" class="tr1">
                8
            </td>
            <td id="9" class="tr1">
                9
            </td>
            <td id="0" class="tr1">
                0
            </td>
        </tr>
        <tr>            
          <td id="4" class="tr1">
                4
            </td> 
            <td id="5" class="tr1">
                5
            </td> 
            <td id="6" class="tr1">
                6
            </td> 
            <td id="." class="tr1">
                .
            </td> 
        </tr> 
        <tr>             
            <td id="1" class="tr1">
                1
            </td> 
            <td id="2" class="tr1">
                2
            </td> 
            <td id="3" class="tr1">
                3
            </td> 
            <td id="=" class="tr1">
                =
            </td> 
        </tr>
    </tbody>
</table>
Copy after login
Simple calculator
- * /
7 8 9 0
4 5 6 .
1 2 3 =

For this program, the order of judgment is very important, otherwise the " " number will be stored in s2 and s4 instead of s3.

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!

Recommended reading:

Detailed explanation of the use of Vue scope slots

JS implementation evaluation star

The above is the detailed content of JS implements simple four arithmetic operations. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template