1

我正在尝试做同样的事情。“单击”以调用 ajax,但是现在使用 keypress 将放置所有代码并告诉您我认为此错误的位置。

jQuery:

$(document).ready(function () {
    // Call Ajax Click  <----- THIS WORK
    $('.container-list-podcast').on('click', '.link-podcast', function (e) {
        e.preventDefault();
        $('.video').attr('src', this.href);
    });

    // Call Ajax Key Enter  <----- THIS NOT WORK
    $('.container-list-podcast').on('keypress == 13', '.selected', function (e) {
        e.preventDefault();
        $('.video').attr('src', this.href);
    });

});

JSFIDDLE 和完整的代码

4

1 回答 1

3

您的事件挂钩不正确,因为您必须通过询问引发keypress. 尝试这个:

// Call Ajax Key Enter
$('.container-list-podcast').on('keypress', '.selected', function (e) {
    e.preventDefault();
    if (e.which == 13) { // keyCode 13 == Enter key
        $('.video').attr('src', this.href);
    }
});
于 2013-08-13T14:32:32.693 回答