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