[點(diǎn)晴永久免費(fèi)OA]【JavaScript】用jQuery獲取和控制table中tr行id和td值
<!DOCTYPE html> <html> <head> <title>點(diǎn)擊</title> <meta content="IE=edge" http-equiv="X-UA-Compatible"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="Content-Language" content="zh-cn" /> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <script type="text/javascript"> $(function(){ //用jQuery獲取table中td值 $("#mytable td").click(function(){ alert("table td值:"+$(this).text()); });
//jQuery獲取table中點(diǎn)擊位置所在行的id $("#mytable td").click(function() { //td的id alert($(this).attr("id")); //tr的id alert($(this).parent().attr("id")); }); }); </script> </head> <body> <table id="mytable" width="640px;" cellpadding="5" cellspacing="1"> <tbody> <tr bgcolor="#DEE9F4" id="tr_1"> <td> 日</td> <td> 一 </td> <td> 二 </td> <td> 三 </td> <td> 四 </td> <td> 五 </td> <td> 六 </td> </tr> <tr bgcolor="#DEE9F4" id="tr_2"> <td> </td> <td> </td> <td> </td> <td> 1 </td> <td> 2 </td> <td> 3 </td> <td> 4</td> </tr> <tr bgcolor="#DEE9F4" id="tr_3"> <td> 5 </td> <td> 6 </td> <td> 7 </td> <td> 8 </td> <td> 9 </td> <td bgcolor="red">10</td> <td>11</td> </tr> <tr bgcolor="#DEE9F4" id="tr_4"> <td> 12 </td> <td> 13 </td> <td> 14 </td> <td> 15 </td> <td> 16 </td> <td> 17 </td> <td> 18 </td> </tr> </tbody> </table> </body> </html> 該文章在 2023/4/28 15:27:12 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |