怎么来判断?
<form name=hrong>
<select name= "yyy " >
<option selected > 正常 </option>
<option> 反常 </option>
</select>
</font>
<input name=txt1 onkeydown= "if(event.keyCode==13)event.keyCode=9 "> <br>
<input name=txt2 onkeydown= "if(event.keyCode==13)event.keyCode=9 "> <br>
<input name=txt3 onkeydown= "if(event.keyCode==13)event.keyCode=9 " onfocus= "mm() "> <br>
</form>
<SCRIPT LANGUAGE= "JavaScript "> <!--
function mm()
{
with(document.hrong)
{
if(!txt1.value || !txt2.value){alert( '有一项为空, 不予计算! '); return;}
var n1 = parseInt(txt1.value)? parseInt(txt1.value) : 0;
var n2 = parseInt(txt2.value)? parseInt(txt2.value) : 0;
txt3.value = n1 + n2;
}
}
//--> </SCRIPT>
在选择反常时txt3里的结果必须为0。
[解决办法]
<script language= "JavaScript "> <!--
function mm()
{
with(document.hrong)
{
if (yyy.options[yyy.selectedIndex].text == '正常 ') {
if (!txt1.value || !txt2.value){
alert( '有一项为空, 不予计算! ');
return;
}
var n1 = parseInt(txt1.value)? parseInt(txt1.value) : 0;
var n2 = parseInt(txt2.value)? parseInt(txt2.value) : 0;
txt3.value = n1 + n2;
}
else if (yyy.options[yyy.selectedIndex].text == '反常 ') {
txt3.value = 0;
}
}
}
//--> </script>
[解决办法]
呵呵,不好意思
没测试正常情况
<html>
<head>
</head>
<body >
<form name=hrong>
<select name= "yyy " id= "yyy " >
<option selected value= "1 "> 正常 </option>
<option value= "0 "> 反常 </option>
</select>
</font>
<input name=txt1 onkeydown= "if(event.keyCode==13)event.keyCode=9 "> <br>
<input name=txt2 onkeydown= "if(event.keyCode==13)event.keyCode=9 "> <br>
<input name=txt3 onkeydown= "if(event.keyCode==13)event.keyCode=9 " onfocus= "mm() "> <br>
</form>
<SCRIPT LANGUAGE= "JavaScript "> <!--
function mm()
{
var txt3=document.getElementById( "txt3 ");
var txt1=document.getElementById( "txt1 ");
var txt2=document.getElementById( "txt2 ");
if(document.getElementById( "yyy ").value== "0 "){
alert( "反常 ");
txt3.value=0;}
else if(document.getElementById( "yyy ").value== "1 "){
if(!txt1.value || !txt2.value){alert( '有一项为空, 不予计算! '); return;}
var n1 = parseInt(txt1.value)? parseInt(txt1.value) : 0;
var n2 = parseInt(txt2.value)? parseInt(txt2.value) : 0;
txt3.value = n1 + n2;
}
}
//--> </SCRIPT>
</body>
</html>