2011-02-06 63 views
0

我有一個頁面有幾個Ajax.InPlaceEditor字段。有些是單行(文本輸入框),有些是多行(textareas)。如何停止Ajax.InPlaceEditor按回車鍵提交?

當用戶在單行框中輸入內容並點擊輸入時,表單提交。不過,我不希望這種情況發生。

這裏是我的代碼有Ajax.InPlaceEditor樣本:

new Ajax.InPlaceEditor(
    'headline', 
    '../scripts/save.php', 
    { 
     submitOnBlur:true, 
     rows:1, 
     okControl:false, 
     cancelControl:false, 
     highlightColor:'transparent', 
     highlightEndColor:'transparent', 
     savingText: 'Saving...' 
    } 
); 

我想保持sumitOnBlur: true如果在所有可能的。

+0

一起使用jQuery和Prototypejs?什麼是美元? jQuery或原型的getByID方法? – BGerrissen 2011-02-06 13:24:52

回答

1

表格由按鍵事件提交。嘗試在不應提交表單的字段上進行抑制:

$('form#form_id input').keypress(function (e) { 
    // Prevent form from submitting on enter key press 
    if (e.keyCode == 13) { // ENTER 
    e.preventDefault(); 
    } 
});