مسج محدد للعناصر القائمة
-
05-09-2019 - |
سؤال
أنا أستخدم 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'});
});
لا تنتمي إلى StackOverflow