A calculator that calculates the amount of water and electricity in the current month: after entering each item, click the mouse in any blank area on the page and the page automatically calculates the result !, Each item must be filled in. You can enter 0.
Script function StorePage () {d = document; t = d. selection? (D. selection. type! = 'None '? D. selection. createRange (). text: '') :( d. getSelection? D. getSelection (): ''); void (keyit = window. open (' http://www.365key.com/storeit.aspx?t= '+ Escape (d. title) + '& u =' + escape (d. location. href) + '& c =' + escape (t), 'keyit', 'scrollbars = no, width = 475, height = 575, left = 75, top = 20, status = no, resizable = yes '); keyit. focus ();} script <! -- CTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt-- > <Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "/> <style type =" text/css "> body {font-size: 12px; text-align: center;} td {font-size: 12px ;}. outtab {border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: # CCCCCC; Border-right-color: # CCCCCC; border-bottom-color: # CCCCCC; border-left-color: # CCCCCC; }# main {border: 1px solid # CCCCCC; width: 600px; height: 200px; text-align: left; padding: 10px ;} </style> script // digital verification part // JavaScript Document // controls the input in the form of function CheckNum (thetxtNum) {var _ value = thetxtNum. value; var kc = window. event. keyCode; if (kc = 110 | kc = 190) // if yes. {if (_ value. length = 0) // The first input is not allowed. {Alert ("cannot begin with a decimal point! "); Window. event. returnValue = false; return;} if (_ value. indexOf (". ")> = 0) // if it already exists. {// window. event. keyCode = 8; alert ("the decimal point cannot be entered again! "); Window. event. returnValue = false; return ;}// alert (kc); if (kc >=48 & kc <= 57) | (kc> = 96 & kc <= 105) | kc = 110 | kc = 190) // if it is a number or. {window. event. returnValue = true; return;} else if (kc = 8) // if it is a return {thetxtNum. select (); thetxtNum. value = ""; thetxtNum. focus (); window. event. returnValue = false; return;} else if (kc = 13) {window. event. keyCode = 9; window. event. returnValue = true; return;} e Lse if (kc = 9 | kc = 45 | kc = 46 | kc = 16 | kc = 17 | kc = 18 | kc = 20 | (kc> = 112 & kc <= 123 )) {window. event. returnValue = true; return;} else {// window. event. keyCode = 8; alert ("enter a number! "); ThetxtNum. value = 0; window. event. returnValue = false; return ;}// retain the first digit of the decimal point. function Transfer (thetxtNum) {var _ value = parseFloat (thetxtNum. value); if (isNaN (_ value) {return;} thetxtNum. value = _ value. toFixed (2);} // digit Verification Section ----- end // input Date year and month function writeyearmonth () {var myDate = new Date (); myDate. getFullYear (); // obtain the complete year (4 digits, 1970 -????) MyDate. getMonth (); var rqstr = ""; rqstr = myDate. getFullYear () + "year" + myDate. getMonth () + "month"; document. write (rqstr);} script <p id = "main"> <ul> <li> script writeyearmonth (); script </li> <li> water: Initiation <input onkeydown = "CheckNum (this)" onblur = "dosum ()" style = "WIDTH: 50px "name =" s1 "/> stop <input onkeydown =" CheckNum (this) "onblur =" dosum () "style =" WIDTH: 50px "name =" s2 "/> unit price <input onkeydown =" CheckNum (this) "Onblur =" dosum () "style =" WIDTH: 50px "name =" s3 "/> additional <input onkeydown =" CheckNum (this) "onblur =" dosum () "style =" WIDTH: 50px "name =" s4 "/> </li> <li> power: Start <input onkeydown =" CheckNum (this) "onblur =" dosum () "style =" WIDTH: 50px "name =" d1 "/> stop <input onkeydown =" CheckNum (this) "onblur =" dosum () "style =" WIDTH: 50px "name =" d2 "/> unit price <input onkeydown =" CheckNum (this) "onblur =" dosum () "style =" WIDTH: 50px" Name = "d3"/> additional <input onkeydown = "CheckNum (this)" onblur = "dosum ()" style = "WIDTH: 50px "name =" d4 "/> </li> <li> gas: Starting degree <input onkeydown =" CheckNum (this) "onblur =" dosum () "style =" WIDTH: 50px "name =" q1 "/> stop <input onkeydown =" CheckNum (this) "onblur =" dosum () "style =" WIDTH: 50px "name =" q2 "/> unit price <input onkeydown =" CheckNum (this) "onblur =" dosum () "style =" WIDTH: 50px "name =" q3 "/> additional <input onkeydown =" CheckN Um (this) "onblur =" dosum () "style =" WIDTH: 50px "name =" q4 "/> </li> <li> Note: after entering each item, click the mouse in any blank area on the page to automatically calculate the result! </Li> </ul> <table cellspacing = "0" bordercolordark = "# ffffff" cellpadding = "0" width = "646" align = "left" bordercolorlight = "# 000000 "border =" 1 "> <tbody> <tr> <td align =" center "width =" 90 "> name </td> <td align =" center "width = "90"> starting degree (ton/Degree/party) </td> <td align = "center" width = "90"> stop (ton/Degree/party) </td> <td align = "Central" width = "90"> quantity (tons/Degree/party) </td> <td align = "center" width = "90"> unit price (RMB) </td> <td align = "center" width = "90"> additional amount (RMB) </td> <td align = "center" width = "90"> total amount (RMB) </td> </tr> <td align = "center"> water </td> <td id = "a1" align = "right"> </td> <td id = "a2" align = "right"> </td> <td id = "a3" align = "right"> </td> <td id =" a4 "align =" right "> </td> <td id =" a5 "align =" right "> </td> <td id =" a6 "align =" right "> </td> </tr> <td align =" center "> electricity </td> <td id =" b1 "align =" right "> </td> <td id = "b2" align = "right"> </td> <td id = "b3" align = "right"> </td> <td id = "b4" align = "right"> </td> <td id = "b5" align = "right"> </td> <td id = "b6" align = "right"> </td> </tr> <td align = "center"> gas </td> <td id = "c1" align = "right"> </td> <td id = "c2" align = "right"> </td> <td id = "c3" align = "right"> </td> <td id = "c4" align = "right"> </td> <td id = "c5" align = "right"> </td> <td id = "c6" align = "right"> </td> </tr> <td align = "left" colspan = "6"> script writeyearmonth (); total scripts (RMB) </td> <td id = "hj" align = "right"> </td> </tr> </tbody> </table> </p> script // calculate the input result to TD function dosum () {var sum1, sum2, sum3, sum4; var sl1, sl2, sl3; sum1 = 0; sum2 = 0; sum3 = 0; sum4 = 0; sl1 = 0; sl2 = 0; sl3 = 0; var s1, s2, s3, s4, d1, d2, d3, d4, q1, q2, q3, q4; s1 = parseFloat (document. all. s1.value); // value s2 = parseFloat (document. all. s2.value); s3 = parseFloat (document. all. s3.value); s4 = parseFloat (document. all. s4.value); d1 = parseFloat (document. all. d1.value); d2 = parseFloat (document. all. d2.value); d3 = parseFloat (document. all. d3.value); d4 = parseFloat (document. all. d4.value); q1 = parseFloat (document. all. q1.value); q2 = parseFloat (document. all. q2.value); q3 = parseFloat (document. all. q3.value); q4 = parseFloat (document. all. q4.value); sl1 = (s2-s1); // quantity sl2 = (d2-d1); sl3 = (q2-q1); sum1 = sl1 * s3 + s4; // amount sum2 = sl2 * d3 + d4; sum3 = sl3 * q3 + q4; sum4 = sum1 + sum2 + sum3; // enter the corresponding TD document. all. a1.innerHTML = s1; document. all. a2.innerHTML = s2; document. all. a3.innerHTML = sl1; document. all. a4.innerHTML = s3; document. all. a5.innerHTML = s4; document. all. a6.innerHTML = sum1; document. all. b1.innerHTML = d1; document. all. b2.innerHTML = d2; document. all. b3.innerHTML = sl2; document. all. b4.innerHTML = d3; document. all. b5.innerHTML = d4; document. all. b6.innerHTML = sum2; document. all. c1.innerHTML = q1; document. all. c2.innerHTML = q2; document. all. c3.innerHTML = sl3; document. all. c4.innerHTML = q3; document. all. c5.innerHTML = q4; document. all. c6.innerHTML = sum3; document. all. hj. innerHTML = sum4;} script
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]