2016-07-25 11 views
0

私のテーブルリストのインデックスをクリックしないで表示すると、SOや他のソースのほとんどの例にあります。<tr>動的テーブルリストのテーブル行の位置を指定する方法

<script src="../js/jquery-2.0.2.min.js"></script> 
<table id="tableID" width="200" border="1"> 
    <tr> 
    <td class="sm">5</td> 
    <td class="pos"></td> 
    </tr>  
    <tr> 
    <td class="sm">4</td> 
    <td class="pos"></td> 
    </tr> 
    <tr> 
    <td class="sm">5</td> 
    <td class="pos"></td> 
    </tr> 
</table> 
<script> 
var position = getElementsByClassName("pos").index();; 
document.getElementsByClassName("pos")[0].textContent = position; 
</script> 

私はここで

enter image description here

答えて

1
$('td.pos').each(function(){ 
$(this).html($(this).parent().index()+1); 
}); 

のような結果を与えるために、上記の表を望むがDEMO

です
関連する問題