将变量创建到路径JSON是由jQuery执行的操作

Create variable to a path JSON is an action performed by jQuery

本文关键字:jQuery 执行 操作 是由 JSON 变量 创建 路径      更新时间:2023-09-26

需要加载的每个项目的"摘要"都是从一个JSON开始的。我创建了这个变量,但这似乎是错误的,因为我总是返回第一个项,而不是当前项。

javascript:

// it seems to be wrong
var description = json.query.results.channel.item.map(function (item) {
    return item.summary;
});
var i = 0;
$(".selected").each(function () {
    if ($(this).css("background") == "red") i = $(this).index();
});

JSFIDDLE

// Call Ajax Key Enter
$(document).on('keypress', function (e) {             
    if (e.which == 13) {
        $('.description').html(description[$(".selected").index()]);
    }
    e.preventDefault();
});    

尝试此修改http://jsfiddle.net/2NmnB/4/

$(document).on('keypress', function (e) {
                if (e.which == 13) {
                    var x = $('li').index( $('.selected'));
                    $('.description').html(description[x]);
                }
                e.preventDefault();
            });