Compile a simple calculator in JavaScript and write it in javascript.

Source: Internet
Author: User

Compile a simple calculator in JavaScript and write it in javascript.

This example describes how to compile the code of a simple calculator in JavaScript. Share it with you for your reference. The details are as follows:
The running effect is as follows:

The Code is as follows:

<! DOCTYPE html> 

Js Code:

<Script> var num = 0; // define the first input data function jsq (num) {// obtain the current input if (num = "%") {document. getElementById ('screenname '). value = Math. round (document. getElementById ('screenname '). value)/100;} else {document. getElementById ('screenname '). value + = document. getElementById (num ). value ;}} function eva () {// calculate the input result document. getElementById ("screenName "). value = eval (document. getElementById ("screenName "). value);} function clearNum () {// clear 0 document. getElementById ("screenName "). value = null; document. getElementById ("screenName "). focus ();} function tuiGe () {// return var arr = document. getElementById ("screenName"); arr. value = arr. value. substring (0, arr. value. length-1) ;}</script>

A simple calculator is implemented in this way. You can also use javascript to write a calculator, hoping to help you learn it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.