0
我正在使用jQuery。我有一個像下面的一些代碼 -Jquery - 如何訪問被點擊的元素來運行一個函數?
---- ----- HTML
<table>
<tr>
<td class="cell" id="cell1" ></td>
<td class="cell" id="cell2"></td>
<td class="cell" id="cell3" ></td>
</tr>
<tr>
<td class="cell" id="cell4"></td>
<td class="cell" id="cell5"></td>
<td class="cell" id="cell6"></td>
</tr>
</table>
--- JS ----
$(".cell").click(function() {
do_something();
}
function do_something(){
// I want to print the id of the cell that was clicked here .
}
如何訪問導致函數運行的元素?比如,對於上面的代碼,我要訪問從功能do_Something()
他要顯示的ID沒有價值,那麼試試這個:$(本).attr( 'ID') – tuffkid 2013-03-24 08:42:58
'this.id'好得多... – 2013-03-24 08:43:18