剛做了這個輸入 - 提交表單jQuery腳本。在你開始洪水之前「不要這樣做嗎?」 - 是的,如果你有一個實際的提交按鈕,它會。jQuery自動提交輸入,請求改進
但我使用<a>
標籤樣式作爲按鈕來提交表單。除非javascript被禁用,否則<noscript>
將顯示實際的標準外觀提交按鈕。
它應該處理瀏覽器的默認自動完成功能,如果按下向上/向下箭頭鍵,它會在自動完成列表中上下移動,臨時禁用自動提交輸入。
如果您看到任何警告,或有改進的想法,他們會很多apreciated。
這裏的腳本
// Submit form if focus on inputfields and enter is pressed
// To handle autocomplete, we disable next enter if arrow up/down pressed and autocomplete is not turned off
$('form input:text, form input:password').keyup(function(e){
var arrowKeys = new Array(38, 40);
var key = e.charCode || e.keyCode || 0;
if(key == 13){
if($(this).data('entersubmit')) {
e.preventDefault();
$(this).closest('form').submit();
return false;
}
$(this).data('entersubmit', true);
} else if($.inArray(key, arrowKeys) > -1) {
if($(this).attr('autocomplete') != 'off') {
$(this).data('entersubmit', false);
}
}
})
.blur(function(){
$(this).data('entersubmit', true);
})
.focus(function(){
$(this).data('entersubmit', true);
});
我大概可以省略onFocus或onBlur – Phliplip 2010-11-23 12:39:58