日期:2014-05-17  浏览次数:21008 次

执行判断函数的问题(急,在线等)
<script   language=javascript>
function   chkk(){
if(document.ff.sh.checked==false){
alert( "请点击审核 ");
document.ff.sh.focus();
return   false;}
}
</script>

<form   name=ff   action= "*.asp "   method=post   onsubmit= "return   chkk() ">
<%if   s   =   1   then%>
    <input   type= "radio "   name= "sh "   value= "1 ">  
    审核  
    <input   type= "submit "   name= "Submit "   value= "提交 ">
    <%else%>
    <input   type= "radio "   name= "sh "   value= "2 ">  
    审核   <input   type= "radio "   name= "sh "   value= "3 ">  
    未审核  
    <input   type= "submit "   name= "Submit "   value= "提交 ">
    <%end   if%>
</form>

如果s=1,就会判断审核是否被选中
如果s=2,就不会执行上面的函数,直接跳到下一页
为什么,问题出在哪里?
谢谢!

------解决方案--------------------
s=2 sh有2个啊,要用数组了
document.ff.sh[0].checked

所以先要判断sh是不是数组
if(document.ff.sh.length) ...
------解决方案--------------------
function chkk(){
if(typeof(document.ff.sh.length)== "undefined ")
{
if (document.ff.sh.checked==false)
{
alert( '请点击审核! ');
return false;
}
}
else
{
arr = document.ff.sh;
var s=-1;
for (var i=0;i <arr.length ;i++ )
{
if(arr[i].checked)
{
s=s+1;
}
}
if(s==-1){
alert( "请点击审核 ");
return false;
}
}
}