2010-07-27 41 views
1

IM在JavaScript創建TD我想,這是什麼"<td id='abc'>"我怎麼可以設置在JavaScript中我使用setAtteribute()的TD標識不工作如何與一些價值在TD中的JavaScript設置ID

我的代碼看起來象

var cell4 = row.insertCell(3); 
      cell4.innerHTML = "Song"; 
    var cell5 = row.insertCell(4); 
    cell5.setAttribute('id','example1'); 

我想設定值例如TD的ID plz幫助

回答

1
cell5.attr("id","example1"); //jquery 
+1

這是行不通的,因爲cell5不是一個jQuery對象。原來的海報也沒有使用jQuery,而是純粹的JavaScript。 – 2010-07-27 10:48:40

2

使用javascript (W/O的jquery)

 cell4.id="some_td_id" 

例如

 advTable=document.getElementById("advance_option"); 
     advRow = advTable.insertRow(advTable.rows.length); 
     advRow.id ="tr_id" // Here you can set tr's id 
     cell0=advRow.insertCell(0); 
     cell0.id="td_id" // Here you can set td's id 
    cell1=advRow.insertCell(1); 
相關問題