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中为特定目的生成的,那我该怎么办?

4

4 回答 4

3

jQuery:

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

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

您可以将 $(document) 替换为 $("id of focus element") 以限制按键的范围。

于 2012-12-18T16:14:11.633 回答
0

Surround this with form tags and then use, change the button type to submit.

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

Not tested it though :)

于 2012-12-18T16:16:58.693 回答
0

You can use jQuery syntax

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

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

Replace document with the id of your modal or input (ex : '#modal') and 'button' with your button id (ex 'myButton')

于 2012-12-18T16:17:01.803 回答
0

另一个 jquery 示例可能是这样的:

$(document).on("keydown keypress", function (e) {
    if (e.which == 13) {
        e.preventDefault();
        forgotPassAjax();
    }
});
于 2012-12-18T16:28:01.997 回答