我使用jQuery和jQuery用户界面。

使用的getJSON功能,我们正在创建列表元素并将它们附加到一个OL元件。下面的代码:

$.getJSON("http://localhost/b/t.php", function(data){

        $.each(data, function(i, thet){
            //alert(thet.fname)
            var t = '<li class="name" id="p' + thet.pid + '">' + thet.pid + ' ' + thet.fname + ' ' + thet.lname + '</li>';

            $(t).appendTo("#" + thet.tour + 'list');

        });
    });

我想选择使用jQuery列表元素。如果我手动放在HTML页面的列表,它会工作。然而,编程追加列表项目的OL,不允许它选择 - 至少从我已经试过

$('li:last-child').css({color: 'red', backgroundColor: 'black'});

我使用的ID和许多其他多个选择器,但没有成功尝试。

任何想法?

有帮助吗?

解决方案

当你试图执行该命令的颜色列表中的项目?我相信,你必须将其投入的getJSON回调函数的末尾,如下所示:

$.getJSON("http://localhost/b/t.php", function(data){
    $.each(data, function(i, thet){
        //alert(thet.fname)
        var t = '<li class="name" id="p' + thet.pid + '">' + thet.pid + ' ' + thet.fname + ' ' + thet.lname + '</li>';

        $(t).appendTo("#" + thet.tour + 'list');
    });
    $('li:last-child').css({color:'red',backgroundColor:'black'});
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top