<!DOCTYPE HTML><HTML> <Head> <title>Event</title> <Scripttype= "Text/javascript"> functioncount () {varFnum=document.getElementById ("txt1"). Value;//gets the value of the first input box varSnum=document.getElementById ("txt2"). Value;//gets the value of the second input box varsel=document.getElementById ("Select"). Value//gets the value of the selection box varsum=0; Switch(SEL) {//gets the value selected by the drop-down box to change the subtraction algorithm Case "+": Sum=parsefloat (fnum)+parsefloat (snum);//Value values obtained by getElementById by default to String type Break; Case "-": Sum=Fnum-Snum; Break; Case "*": Sum=Fnum*Snum; Break; default: Sum=Fnum/Snum; Break; } //set the value of the result input boxdocument.getElementById ("Fruit"). Value=sum; } </Script> </Head> <Body> <inputtype= ' text 'ID= ' Txt1 '/> <SelectID= ' SELECT '> <optionvalue= ' + '>+</option> <optionvalue="-">-</option> <optionvalue="*">*</option> <optionvalue="/">/</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></HTML>
:
Ability to implement basic arithmetic operations, a selection box, two text boxes, a button
Main Event Response:
- OnClick mouse click event (usually used with the button)
- onmouseover Mouse over events (commonly used for hints)
- onmouseout Mouse Move Event
- onchange text Box content Change Event
- Onselect text box content is selected event
- onfocus Cursor Focus Event
- onblur Cursor Leave event
- OnLoad Load event (the OnLoad event is triggered when the page is loaded, and the event is written in the <body> tab.) Write which to listen to which. )
- OnUnload Unload event (when the user exits the page, such as the page close "close refers to the page jump", the refresh is triggered)
The effect of the OnLoad event:
Loading events can be used to adjust the page style by JS code before the page is loaded, for example, after detecting the browser width screen resolution, adjust the corresponding size of the page
JS Learning-Incident Response summary-Simple calculator