1

当您单击“输入”时,我还想进行 ajax 操作,目前这仅用于单击鼠标,一个加载的插件来选择项目(jquery.keynav.js)。有谁知道该怎么做?

jQuery

var main = function () {
    var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D'http%3A%2F%2Frss.cnn.com%2Fservices%2Fpodcasting%2Fac360%2Frss.xml'%20AND%20itemPath%3D%22%2F%2Fchannel%22&format=json&diagnostics=true&callback=?";

    $.ajax({
        type: 'GET',
        url: url,
        async: false,
        jsonpCallback: 'jsonCallback',
        contentType: "application/json",
        dataType: 'jsonp',
        success: function (json) {
            var titles = json.query.results.channel.item.map(function (item) {
                return item.title;

            });

            var urls = json.query.results.channel.item.map(function (item) {
                return item.origLink;

            });

            $(".container-list-podcast ul").append('<li>' + titles.join('</li><li>'));
            $(".container-list-podcast ul li").each(function (key, value) {
                var text = $(this).text();
                $(this).html('<a class="link-podcast" href="' + urls[key] + '">' + text + '</a>');
            });

            a = $('.nav_holder li a').keynav(function () {
                return window.keyNavigationDisabled;
            });


        },
        error: function (e) {
            console.log(e.message);
        }
    });

}(jQuery);

...继续

jsfiddle

4

1 回答 1

1

你应该使用密钥代码

$("#elementId").keypress(function (e) {
   if (e.keyCode == 13) {
      alert('Enter key pressed!');
      //TODO: call Ajax here 
    }
});
于 2013-08-13T02:31:06.990 回答