Javascript to implement a simple calculator effect [recommended] _ javascript tips-js tutorial

Source: Internet
Author: User
The following small series will bring you a javascript simple calculator effect [recommended ]. The editor thinks it is quite good. Now I will share it with you and give you a reference for the final result, such as-2. There is a bug: The result is correct by clicking "%" after an integer, if % is clicked after the decimal point, the result is incorrect! Everything else is normal. Please advise: the input value is of the string type. In JS, how can I correct the if part in-1 ??

Figure-1

Figure 2

The HTML code is as follows:

Simple calculator @ walker

Welcome to JavaScript calculator feedback

The CSS code is as follows:

 

The javascript code is as follows:

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

The above javascript Implementation of the simple calculator effect [recommended] is all the content shared by the small editor. I hope to give you a reference, but also hope you can support the home of foot.

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.