سؤال

أنا أستخدم jQuery and jquery ui.

باستخدام وظيفة 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'});

لقد حاولت استخدام المعرف والعديد من المحددين المتعددين الآخرين، دون جدوى.

أيه أفكار؟

هل كانت مفيدة؟

المحلول

عندما تحاول تنفيذ هذا الأمر الذي تلوين العناصر القائمة؟ أعتقد أنك ستحتاج إلى وضع في نهاية وظيفة رد الاتصال في 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