日期:2014-05-16 浏览次数:20514 次
1:<input type="text" value="" id="t1" /> <br/>
2:<input type="text" value="" id="t2" /> <br/>
3:<input type="text" value="" id="t3" /> <br/>
4:<input type="text" value="" id="t4" /> <br/>
<input type="button" onclick="Check()" value="提交"/>
<script >
var $ = function (el) {
return (typeof el == 'object')?el:document.getElementById(el);
};
var Check=function(){
v1=$("t1").value;
v2=$("t2").value;
v3=$("t3").value;
v4=$("t4").value;
if(v2/v1==2 && v3/v1==3 && v4/v1==4)
{
alert("成功!");
}
else
{
alert("失败!");
}
};
</script>
------解决方案--------------------
<input type="text" name="t1" />
<input type="text" name="t2" />
<input type="text" name="t3" />
<input type="text" name="t4" />
<input type="button" value="check" onclick="check()" />
<script>
var check = function(){
var objs = new Array(t1 ,t2 ,t3 ,t4);
for(var i=0;i<objs.length;i++)
{
if(objs[i].value == "")
{
alert("input "+ (i+1) +" is null");
break;
}
if(isNaN(objs[i].value/1))
{
alert("input "+ (i+1) +" is not bumber!");
break;
}
}
if((objs[0].value*1 + objs[3].value*1) != (objs[1].value*1 + objs[2].value*1))
{
alert("is not rule");
}
};
</script>