2011-03-30 5 views
4

jQuery 1.4.2를 사용하여 테이블 셀 값을 업데이트하는 데 문제가 있습니다. Firefox와 Safari에서는 모두 작동하지만 IE8과 IE9는 아무 것도하지 않습니다. 경고, 오류 또는 그 곳을 찾을 수있는 힌트를 줄 수있는 어떤 것도 없습니다.jQuery를 사용하여 테이블 셀 값을 업데이트하는 방법

<table id="test"> 
    <tr id="1"> 
     <td id="name">sample name</td> 
     <td id="schedule">sample value</td> 
     <td id="day">sample value</td> 
    </tr> 
    <tr id="2"> 
     <td id="name">sample name</td> 
     <td id="schedule">sample value</td> 
     <td id="day">sample value</td> 
    </tr> 
    <tr id="3"> 
     <td id="name">sample name</td> 
     <td id="schedule">sample value</td> 
     <td id="day">sample value</td> 
    </tr> 
</table> 

나는 아약스 호출을 실행하고 JSON 데이터를 점점 오전 :

표는 다음과 같습니다

{"Test": [ 
     {"id":"1", "name":"John", "day":"Monday"}, 
     {"id":"2", "name":"Marry", "day":"Thursday"} 
]} 

데이터가 수신되는 루프가되면 이는 JSON 데이터 세트 및 업데이트 해당 열을 반복 수신 된 데이터는 다음과 같습니다 :

$.each(json.Tests, function(){ 
    /* update test with details */ 

    var test = this.hash; 

    /*set values for each test */ 
    $("table#test tr[id=" + test + "]").find("#name").html(this.name); 
    $("table#test tr[id=" + test + "]").find("#schedule").html(this.status); 
    $("table#test tr[id=" + test + "]").find("#day").html(this.changed); 
}); 

앞서 언급했듯이 사파리와 파이어 폭스에서 테스트 한 모든 것은 잘 작동하지만 IE8과 IE9는 아무 것도하지 않는 것 같습니다.

답변

6

id 속성은 고유 한 식별자로 사용되어야한다고 생각합니다. td 요소의 id 속성을 클래스 속성 또는 이름 속성으로 변경하는 방법은 어떻습니까? 나는 IE가 혼란 스럽다고 생각합니다. 당신이 고유 ID를 유지하고 클래스에 TD의 id 속성을 변경하는 경우

또한, 당신은 같은에 코드를 변경할 수 있습니다

$("#" + test + " td.name").html(this.name); 

그리고 숫자가 꽤 ​​많은 것을 나타낼 수 있기 때문에 접두어 ID 접두사가있는 ID는 좋을 것입니다.

$("#thing-" + test + " td.name").html(this.name); 

그리고 HTML은 다음과 같을 것이다 : 뭔가 같이 할 수

<table id="test"> 
    <tr id="thing-1"> 
     <td class="name">sample name</td> 
     <td class="schedule">sample value</td> 
     <td class="day">sample value</td> 
    </tr> 
    <tr id="thing-2"> 
     <td class="name">sample name</td> 
     <td class="schedule">sample value</td> 
     <td class="day">sample value</td> 
    </tr> 
    <tr id="thing-3"> 
     <td class="name">sample name</td> 
     <td class="schedule">sample value</td> 
     <td class="day">sample value</td> 
    </tr> 
</table> 

희망!

+1

여기에 JSFiddle이 나와 있습니다 (일부 자바 스크립트 수정과 함께) http://jsfiddle.net/eFHZz/4/ –

+0

답장을 보내 주셔서 감사합니다. – m1k3y3

0

ID는 숫자로 시작하지 않아야합니다. 아마 IE9는 다른 브라우저처럼 용서하지 않습니다.

+0

괜찮습니다. 테스트 해 보겠습니다. – m1k3y3

+0

아니요, 도움이되지 않았습니다 – m1k3y3

0

스크립트를 테스트 할 수있는 URL이 있습니까?

+0

불행히도 로컬 호스트에만 있습니다 – m1k3y3

+0

Demoscript를 업로드 할 수 있습니까? –

관련 문제