<html> <head> <script language=JavaScript> function AA() { var LINT_T1 = document.getElementById("t1").value; var LINT_T2 = document.getElementById("t2").value; if(LINT_T1 == "") { LINT_T1 = 0; } if(LINT_T2 == "") { LINT_T2 = 0; } document.getElementById("t3").value = parseInt(LINT_T1) + parseInt(LINT_T2); } </script> </head> <body> <INPUT type="text" name="t1" id="t1" onpropertyChange="AA()"> <INPUT type="text" name="t1" id="t2" onpropertyChange="AA()"> <INPUT type="text" name="t1" id="t3"> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> new document </title> <meta name="generator" content="editplus" /> <meta name="author" content="Gao YiXiang" /> <meta name="email" content="yixianggao@126.com" /> <meta name="keywords" content="javascript dhtml dom" /> <meta name="description" content="I love web development." /> </head> <body> <input type="text" id="n1" /> +<input type="text" id="n2" /><br /> <input type="button" id="calc" value="Sum" /><input type="text" id="sum" /><br /> <script type="text/javascript"> <!-- calc.onclick = function() { var num1 = parseInt(n1.value); var num2 = parseInt(n2.value); // 容错处理 if (isNaN(num1)) num1 = 0; if (isNaN(num2)) num2 = 0; sum.value = num1 + num2; }; //--> </script> </body> </html>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script> function Compupte() { var op1=document.getElementById("op1"); var op2=document.getElementById("op2"); var result=document.getElementById("result"); if(op1.value==""||isNaN(op1.value)) {alert('操作数1不能为空并且不能为非整数!');op1.focus();return;} if(op2.value==""||isNaN(op2.value)) {alert('操作数2不能为空并且不能为非整数!');op2.focus();return;} result.value=parseFloat(op1.value)+parseFloat(op2.value); } </script> </head> <body> <input type='text' id='op1'/>+ <input type='text' id='op2'/>= <input type='text' id='result'/> <br/> <input type="button" value="计算" onclick="Compupte()"/> </body> </html>
<html> <head> <script language=JavaScript> function AA() { var LINT_T1 = document.getElementById("t1").value; var LINT_T2 = document.getElementById("t2").value; if(LINT_T1 == "" || isNaN(LINT_T1)) { LINT_T1 = 0; } if(LINT_T2 == "" || isNaN(LINT_T2)) { LINT_T2 = 0; } document.getElementById("t3").value = parseInt(LINT_T1) + parseInt(LINT_T2); } </script> </head> <body> <INPUT type="text" name="t1" id="t1" onpropertyChange="AA()"> <INPUT type="text" name="t1" id="t2" onpropertyChange="AA()"> <INPUT type="text" name="t1" id="t3"> </body> </html>