用jQuery获取table中行id和td值的实现代码
用jQuery获取table中行id和td值的实现代码
<%@pagelanguage="java"pageEncoding="UTF-8"%> <% Stringpath=request.getContextPath(); %> <!DOCTYPEhtml> <htmllang="zh-cn"> <head> <title>点击</title> <metacontent="IE=edge"http-equiv="X-UA-Compatible"> <metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/> <metahttp-equiv="Content-Language"content="zh-cn"/> <metaname="author"content="linjiqin218@126.com"/> <metaname="Copyright"content="parami|毛票票"/> <metahttp-equiv="pragma"content="no-cache"> <metahttp-equiv="cache-control"content="no-cache"> <metahttp-equiv="expires"content="0"> <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"> <metahttp-equiv="description"content="Thisismypage"> <jsp:includepage="/demo/base/js_bootstrap.jsp"/> <scripttype="text/javascript"> $(function(){ //用jQuery获取table中td值 $("#mytabletd").click(function(){ alert("tabletd值:"+$(this).text()); }); //jQuery获取table中点击位置所在行的id $("#mytabletd").click(function(){ //td的id alert($(this).attr("id")); //tr的id alert($(this).parent().attr("id")); }); }); </script> </head> <body> <tableid="mytable"width="708px;"cellpadding="5"cellspacing="1"> <tbody> <trbgcolor="#DEE9F4"id="tr_1"> <tdalign="center">日</td> <tdalign="center">一</td> <tdalign="center">二</td> <tdalign="center">三</td> <tdalign="center">四</td> <tdalign="center">五</td> <tdalign="center">六</td> </tr> <trbgcolor="#DEE9F4"id="tr_2"> <tdalign="center"> </td> <tdalign="center"> </td> <tdalign="center"> </td> <tdalign="center">1</td> <tdalign="center">2</td> <tdalign="center">3</td> <tdalign="center">4</td> </tr> <trbgcolor="#DEE9F4"id="tr_3"> <tdalign="center">5</td> <tdalign="center">6</td> <tdalign="center">7</td> <tdalign="center">8</td> <tdalign="center">9</td> <tdalign="center"bgcolor="red">10</td> <tdalign="center">11</td> </tr> <trbgcolor="#DEE9F4"id="tr_4"> <tdalign="center">12</td> <tdalign="center">13</td> <tdalign="center">14</td> <tdalign="center">15</td> <tdalign="center">16</td> <tdalign="center">17</td> <tdalign="center">18</td> </tr> </tbody> </table> </body> </html>
以上这篇用jQuery获取table中行id和td值的实现代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。