表单按钮不会在IE中提交

时间:2012-06-07 08:53:37

标签: javascript button internet-explorer-9

我有一个表单,只是验证用户的年龄然后提交它。该表格在FF,Safari和amp; Chrome但不在IE 9上(我现在只在IE9上测试过它。)

这是javascript

 <script type="text/ecmascript">
         function CalculateAge() {

        var a= document.getElementById("c").value;
         var d=document.getElementById("d").value;
         var m=document.getElementById("m").value;
         var y=document.getElementById("y").value;



         if (d != \'0\' && m != \'0\' && y != \'0\' ) {

            now = new Date()



            if (d) {

               /* born = new Date(y, d, m);

                age = Math.floor((now.getTime() - born.getTime()) / (365.25 * 24 * 60 * 60 * 1000)); */
                //from php spence

            /* now.getDate();//daty of month 1-30
            now.getFullYear();//four digits
            now.getMonth();//return month from 0-11
            */
            year_diff =now.getFullYear() - y;
            month_diff= (now.getMonth()+1)-m;
            day_diff=now.getDate()-d;

            if(month_diff<0){ 

            //--year_diff;
            y=year_diff-1;

            }

            else if((month_diff==0) && (day_diff<0)){ 


            //--year_diff;
            y=year_diff-1;

            }else{
            y=year_diff;
            }
            //alert(y);
            //alert(day_diff);
                //alert(year_diff);
                //alert(month_diff);
            //age=year_diff;
            b=a;
            h=new Number(b)+1;
            //alert("You are "+y+" years old and Your Country is "+document.getElementById("c").options[h].text);
            age=y;
            //alert(age);
                if(isNaN(age))

                {

                   alert(\'Input date is incorrect!\');

                }else if(a=="none"){
                alert("please select a country");
                }

                else

                {


                if(a==1||a==2||a==3||a==4||a==5||a==6||a==7||a==8||a==9||a==11||a==14||a==15||a==16||a==17||a==18||a==19||a==20||a==21||a==22||a==23||a==24||a==25||a==27||a==28||a==29||a==30||a==31||a==33||a==34||a==35||a==36||a==37||a==38||a==39||a==40||a==41||a==42||a==43||a==44||a==45||a==46||a==47||a==48||a==49||a==50||a==51||a==52||a==53||a==55||a==56||a==57||a==58||a==60||a==61||a==63||a==64||a==65||a==66||a==67||a==68||a==69||a==70||a==71||a==72||a==73||a==74||a==76||a==83||a==84||a==85||a==89||a==90||a==91||a==93||a==96||a==97||a==98||a==99||a==100||a==102||a==103||a==104||a==105||a==106||a==107||a==108||a==109||a==110||a==111||a==112||a==113||a==114||a==115||a==116||a==117||a==118||a==119||a==120||a==121||a==122||a==123||a==124||a==125||a==127||a==128||a==129||a==130||a==131||a==136||a==137||a==139||a==140||a==141||a==142||a==143||a==144||a==145||a==146||a==147||a==148||a==149||a==151||a==152||a==154||a==155||a==156||a==157||a==158||a==159||a==160||a==162||a==163||a==164||a==167||a==168||a==170||a==171||a==172||a==174||a==175||a==176||a==177||a==178||a==179||a==180||a==182||a==183||a==184||a==186||a==188||a==190||a==191||a==192||a==193||a==195||a==196||a==197){

if(age>=18){
    document.cookie ="chdg=testcookie; expires=3600; path=/tpfnew";
    window.location="index.php";

}
else{

window.location="reject.html";
}


}else if(a==32||a==92){

if(age>=19){
document.cookie ="chdg=testcookie; expires=3600; path=/tpfnew";
window.location="index.php";

}
else{

window.location="reject.html";
}

}
else if(a==86||a==138){
if(age>=20){
document.cookie = "chdg=hjko; expires=3600; path=/tpfnew";
window.location="index.php";

}
else{

window.location="reject.html";
}


}else if(a==187||a==185||a==161||a==150||a==135||a==133||a==79||a==75||a==12){
if(age>=21){
document.cookie ="chdg=testcookie; expires=3600; path=/tpfnew";
window.location="index.php";

}
else{

window.location="reject.html";
}
}

else if(a==78){
if(age>=25){
document.cookie ="chdg=testcookie; expires=3600; path=/tpfnew"; 
window.location="index.php";

}
else{

window.location="reject.html";
}

}
else if (a){window.location="reject2.html";}





        // window.location="welcome.php";
                    //alert(x+"is the "+age);
                    //alert(age);




            }}

        }else{alert("please select your Date of Birth.")}

    }




    </script>

提前 这是按钮输入

<input type="button" onclick="CalculateAge();" value="Submit" />

2 个答案:

答案 0 :(得分:0)

将它用于“提交”或函数调用。 如果从按钮单击调用CalculateAge()函数然后手动执行提交操作,则可以同时执行这两项操作。像

function CalculateAge(){
  //DO your Stuff here
  jQuery.post(<your URL> , jQuery('#formid).serialize(),function(data){
      jQuery('#your result div').html(data);
  });
}

答案 1 :(得分:0)

这里是jsfiddle代码,行中有一些修改

jsfiddle demo you code

if (d != \'0\' && m != \'0\' && y != \'0\' ) {修改了删除的斜线
alert(\'Input date is incorrect!\');行修改了删除的斜杠

因为这些行上的错误会看到链接以查看修复,但无需修改任何其他内容即可使用

我已经在firefox和ie8

上测试了它们