PHP Exercises-Four Calculator

Source: Internet
Author: User

PHP Exercises-Four calculator

I. Focus: The practice of JS DOM elements

Two. The code is as follows:

<! DOCTYPE html>
<meta charset= "UTF-8"/>
<title> Calculator </title >
<script type= "text/javascript";
function count () {
var d = "";
var A=document.getelementbyid ("Txt1"). Value;
//a value
var b=document.getelementbyid ("Txt2"). Value;
The value of B is
var C=document.getelementbyid ("select"). Value;
The value of the operation symbol
Switch (c)
{
Case "+":
//d = a + B; to an integer
D = parseint (a) +parseint (b);
Break
Case "-":
D = A-B;
Break
Case "":
D = a
b;
Break
Default:
D = A/b;
}
document.getElementById ("fruit"). Value = D;

}
</script>
<body>
Four calculator: <input type= ' text ' id= ' txt1 '/>
<select id= ' SELECT ' >
<option value= ' + ' >+</option>
<option value= "-" >-</option>
<option value= "" ></option>
<option value= "/" >/</option>
</select>
<input type= ' text ' id= ' txt2 '/>
<input type= ' button ' value= ' = ' onclick= ' count () '/>
<input type= ' text ' id= ' fruit '/>
</body>

Three. Page output:

PHP Exercises-Four Calculator

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.