A native JS-written subtraction operation

Source: Internet
Author: User

According to my experience I said more and no one to see, but still simple introduction of the effect bar, you can choose +,-, *,/, to calculate data, like the words paste copy yourself to see it!

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=gb2312" /><title>Untitled Document</title></Head><Body><inputtype= ' text 'ID= ' Txt1 'value="" />    <SelectID= ' SELECT '>        <optionvalue= ' 0 '>+</option>        <optionvalue= "1">-</option>        <optionvalue= "2">*</option>        <optionvalue= "3">/</option>   </Select>   <inputtype= ' text 'ID= ' txt2 '/>    <inputtype= ' button 'value= ' = 'onclick= "count ()" /> <!--Use the = button to invoke the created function to get the result -    <inputtype= ' text 'ID= ' Fruit '/>  </Body><Scripttype= "Text/javascript">     functioncount () {vara=parseint (document.getElementById ("txt1"). Value)//gets the value of the first input box        varb=parseint (document.getElementById ("txt2"). Value)//gets the value of the second input box        varC=parseint (document.getElementById ("Select"). Value)varD=document.getElementById ("Fruit"). ValueSwitch(c) { Case 0: document.getElementById ("Fruit"). Value=Add (A, b); Break;  Case 1:d Ocument.getelementbyid ("Fruit"). Value=sum (A, b); Break;  Case 2:d Ocument.getelementbyid ("Fruit"). Value=app (A, b); Break;  Case 3:d Ocument.getelementbyid ("Fruit"). Value=DIVs (A, b); Break; }//gets the value selected by the drop-down box to change the subtraction algorithm    //set the value of the result input box     }     functionAdd (A, b) {suma=a+b; returnSuma; }         functionsum (A, b) {Sumb=a-b; returnSumb; }         functionapp (A, b) {SUMC=a*b; returnSUMC; }         functionDIVs (A, b) {SUMD=a/b;         returnSUMD; }    </Script> </HTML>

A native JS-written subtraction operation

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.