문제

jQuery와 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'});

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