2012-12-18 23 views
0

我有這樣的事情:提交進入

 <div style="float:left;"><a class="btn btn-primary" href="#sign-in" data-toggle="modal" data-dismiss="modal" ><i class="icon-ok icon-white"></i> Sign-in</a></div> 
     <div> 
      <a href="#" class="btn btn-small" data-dismiss="modal"><i class="icon-remove"></i> Close</a> 
      <button class="btn-success btn-small" type="button" name="submit" value="login" onclick="forgotPassAjax();"><i class="icon-ok icon-white"></i> Send</button> 
     </div> 

在我需要它是上輸入點擊,現在你必須手動用光標點擊按鈕,我如何做到這一點?我以前看過一些JS例子,有沒有更簡單的方法?現在它有一個函數onclick,這是在某些目的在PHP中生成的,所以我該怎麼辦?

+1

'' - Eugh。 '我'意思是*斜體*不是圖標! – Quentin

+1

不要忘記在提問前使用搜索;-) –

+3

@Quentin是按鈕圖標的引導標記。見http://www.plugolabs.com/twitter-bootstrap-button-generator/ –

回答

3

的jQuery:

$(document).on("keydown", processKeyEvents); 
$(document).on("keypress", processKeyEvents); 

function processKeyEvents(event) { 
    if (event.which == 13) { 
     forgotPassAjax(); 
    } 
} 

你可以用$代替$(文件)( 「聚焦元素ID」)限制按鍵的範圍。

+0

請注意,這將通過孔文件工作,不僅在編輯輸入時。 –

+0

謝謝@Megakuh更新... – ATOzTOA

+0

這工作,謝謝 – Vlad

0

用表單標籤圍繞它,然後使用,更改按鈕類型以提交。

$("form-selector").submit(function(e){ 
     e.preventDefault(); 
//perform other stuff here 
}); 

沒有測試它雖然:)

0

您可以使用jQuery語法

$(document).on("keydown", enterPress); 
$(document).on("keypress", enterPress); 

function enterPress(e) { 
    if (e.which == 13) { //if the key press is enter (13) 
     $('button').click(); 
    } 
} 

與模式或輸入的ID替換文件(例如: '#modal')和「按鈕「以您的按鈕ID(如 '則myButton')

0

另一個jQuery的例子可能是這樣的:

$(document).on("keydown keypress", function (e) { 
    if (e.which == 13) { 
     e.preventDefault(); 
     forgotPassAjax(); 
    } 
});