这里的 html 标记有一个表格,我需要在点击时获取 td 的内容并将其保存到隐藏字段中。
JS 小提琴演示
html标记:
<table>
<tr style="color:#333333;background-color:#F7F6F3;" class="odd">
<td style="width:70px;" class=" sorting_1">1</td>
<td class=" "> <span id="ctl00_ContentPlaceHolder1_gvworkcategory_ctl02_lblworkcategory">Customer Relations</span>
</td>
<td>one</td>
<td align="center" style="width:80px;" class=" ">
<img atl="edit" style="border-width:0px;cursor:pointer" src="images/edt1.png" class="update_1" title="Edit" id="ctl00_ContentPlaceHolder1_gvworkcategory_ctl02_Image1">
</td>
<td class=" "><a href="abc.aspx?id=1">View Details</a>
</td>
</tr>
<tr style="color:#333333;background-color:#F7F6F3;" class="odd">
<td style="width:70px;" class=" sorting_1">2</td>
<td class=" "> <span id="ctl00_ContentPlaceHolder1_gvworkcategory_ctl02_lblworkcategory">Marketing </span>
</td>
<td>two</td>
<td align="center" style="width:80px;" class=" ">
<img atl="edit" style="border-width:0px;cursor:pointer" src="images/edt1.png" class="update_2" title="Edit" id="ctl00_ContentPlaceHolder1_gvworkcategory_ctl02_Image1">
</td>
<td class=" "><a href="abc.aspx?id=3">View Details</a>
</td>
</tr>
<tr style="color:#333333;background-color:#F7F6F3;" class="odd">
<td style="width:70px;" class=" sorting_1">3</td>
<td class=" "> <span id="ctl00_ContentPlaceHolder1_gvworkcategory_ctl02_lblworkcategory">General</span>
</td>
<td>three</td>
<td align="center" style="width:80px;" class=" ">
<img atl="edit" style="border-width:0px;cursor:pointer" src="images/edt1.png" class="update_3" title="Edit" id="ctl00_ContentPlaceHolder1_gvworkcategory_ctl02_Image1">
</td>
<td class=" "><a href="abc.aspx?id=3">View Details</a>
</td>
</tr>
</table>
<input id="hdid" type="hidden" />
<input id="hdcol2" type="hidden" />
<input id="hdcol3" type="hidden" />
JavaScript:
$("img[class^='update_']").live('click', function (event) {
var getId = $(this).attr("class")
$("#hdid").val(getId);
alert(getId)
});