JS加法计算 我想在不填写情况下“总数”值为空而不是值为零,请各位大侠帮帮忙
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/...
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
function jisuan(s,s1,s2,zongshu)
{
var s_ = document.getElementById(s);
var s1_ = document.getElementById(s1);
var s2_ = document.getElementById(s2);
var zongshu_ = document.getElementById(zongshu);
var zongshu_value = 0;
if(s_.value!=""){
zongshu_value = zongshu_value + parseInt(s_.value);
}
if(s1_.value!=""){
zongshu_value = zongshu_value + parseInt(s1_.value);
}
if(s2_.value!=""){
zongshu_value = zongshu_value + parseInt(s2_.value);
}
zongshu_.value = zongshu_value;
}
</script>
</head>
<body onload="sheng()" >
<input type="hidden" value="SDGLJSJT" id="xm" />
<p>数
<input type="text" name="s" id="s" onblur="jisuan('s','s1','s2','zongshu')" />
</p>
<p>数1 <input type="text" name="s1" id="s1" onblur="jisuan('s','s1','s2','zongshu')" /></p>
<p>数2 <input type="text" name="s2" id="s2" onblur="jisuan('s','s1','s2','zongshu')" /></p>
<p>总数 <input name="zongshu" type="text" disabled="disabled" id="zongshu" onblur="jisuan('s','s1','s2','zongshu')" /></p>
</body>
</html> 展开
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
function jisuan(s,s1,s2,zongshu)
{
var s_ = document.getElementById(s);
var s1_ = document.getElementById(s1);
var s2_ = document.getElementById(s2);
var zongshu_ = document.getElementById(zongshu);
var zongshu_value = 0;
if(s_.value!=""){
zongshu_value = zongshu_value + parseInt(s_.value);
}
if(s1_.value!=""){
zongshu_value = zongshu_value + parseInt(s1_.value);
}
if(s2_.value!=""){
zongshu_value = zongshu_value + parseInt(s2_.value);
}
zongshu_.value = zongshu_value;
}
</script>
</head>
<body onload="sheng()" >
<input type="hidden" value="SDGLJSJT" id="xm" />
<p>数
<input type="text" name="s" id="s" onblur="jisuan('s','s1','s2','zongshu')" />
</p>
<p>数1 <input type="text" name="s1" id="s1" onblur="jisuan('s','s1','s2','zongshu')" /></p>
<p>数2 <input type="text" name="s2" id="s2" onblur="jisuan('s','s1','s2','zongshu')" /></p>
<p>总数 <input name="zongshu" type="text" disabled="disabled" id="zongshu" onblur="jisuan('s','s1','s2','zongshu')" /></p>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询