javascript onsubmit没有解雇

时间:2015-05-27 03:04:02

标签: javascript onsubmit

我有一个不会开火的功能,我不能为我的生活找出原因。希望有人能看到我所缺少的东西......

页眉

中的

<script type="text/javascript">
<!--
function confTakeIt(asdate,astime,aetime) {
    var ans = confirm("Are you sure you want to signup for this OT?\n\n" + asdate + " " + $astime + " to " + $aetime);  
    if (ans) {
            return true;
    } else {
            return false;
    }
}
//-->
</script>

调用上述功能的页面上的几种不同形式

<form method="post" name="takeIT" id="takeIT" action="takeOT.php" onsubmit="return confTakeIt('Sat 05-30-15','1530','0400')"><input type=hidden name="sumsg"><input type=hidden name="action" value="Add"><input type=hidden name="otid" value="61"><input type="image" src="/images/signup-sign.png" width=70 border=0 alt="Sign Up" value="submit"></form>

<form method="post" name="takeIT" id="takeIT" action="takeOT.php" onsubmit="return confTakeIt('Wed 06-03-15','1800','0630')"><input type=hidden name="sumsg"><input type=hidden name="action" value="Add"><input type=hidden name="otid" value="63"><input type="image" src="/images/signup-sign.png" width=70 border=0 alt="Sign Up" value="submit"></form> 

3 个答案:

答案 0 :(得分:0)

return放入onsubmit,以便简单地调用confTakeIt函数:

onsubmit="confTakeIt('Sat 05-30-15','1530','0400')"

答案 1 :(得分:0)

您使用了错误的变量名称

function confTakeIt(asdate, astime, aetime) {
    //variable names are astime and aetime not $astime and $aetime
    var ans = confirm("Are you sure you want to signup for this OT?\n\n" + asdate + " " + astime + " to " + aetime);
    if (ans) {
        return true;
    } else {
        return false;
    }
}

演示:Fiddle

答案 2 :(得分:0)

你也可以这样做:

只需返回ans的值,同时删除$符号

function confTakeIt(asdate,astime,aetime) {
    var ans = confirm("Are you sure you want to signup for this OT?\n\n" + asdate + " " + astime + " to " + aetime);  
    return ans; //[OK] returns 'true' otherwise 'false'
}