在此函數中,基於輸入的值,表單提交是真/假。爲什麼在這個函數中不能返回true?表單提交
基本上,我的if語句在表單輸入中測試問號。如果有人在那裏,那麼我不希望表單提交給search.php。如果一個問號不存在,其他句子,然後我想要表單提交到search.php。我嘗試使用return true;使.form1提交,但它沒有工作。然後我嘗試$('。form1')。submit(),但是這使得它在提交按下之前提交。
<script>
$(".askInput").keyup(function() {
if ($(this).val().indexOf("?") != -1) {
$(this).css({"color" : "#00bfff", 'border-top-right-radius' : '0px', 'border-bottom-right-radius' : '0px', '-moz-border-top-right-radius' : '0px', '-moz-border-bottom-right-radius' : '0px', '-webkit-border-top-right-radius' : '0px', '-webkit-border-bottom-right-radius' : '0px'});
$('.searchEnter').stop().animate({
marginLeft: "310px"
}, 200);
$('.form1').submit(function() {
return false;
});
} else {
$(this).css({"color" : "#333", 'border-top-right-radius' : '5px', 'border-bottom-right-radius' : '5px', '-moz-border-top-right-radius' : '5px', '-moz-border-bottom-right-radius' : '5px', '-webkit-border-top-right-radius' : '5px', '-webkit-border-bottom-right-radius' : '5px'});
$('.searchEnter').stop().animate({
marginLeft: "250px"
}, 200);
$('.form1').submit(function() {
return true;
});
}
});
</script>
預期的結果是什麼以及「不起作用」? – deceze 2011-04-04 05:14:33
預期的結果是,form .form1應該提交。所以這不起作用。相反,它仍然沒有提交。它基本上像else語句中的所有內容都可以工作,除此之外: $('。form1')。submit(function(){ return true; }); – hubrid 2011-04-04 05:16:28
[\ [jquery \]表單提交可能的重複](http://stackoverflow.com/questions/5535035/jquery-form-submit) – Blender 2011-04-04 06:16:21