jQuery獲取選中TD的值
阿新 • • 發佈:2019-01-09
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>jQuery遍歷表格</title> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> /*<![CDATA[*/ google.load("jquery","1"); /*]]>*/ </script> </head> <style> tr { text-align: center; bgcolor: ##EAEAEA; } td { font-size: 12px; text-decoration: none; color: #355f72; bgcolor: #FFFFFF; } </style> <script language="javascript"> $(document).ready(function() { $("table td").click(function() { var a = $(this).text(); alert(a); }); }); </script> <body> <table width="800" border="1" cellpadding="5" cellspacing="1" bgcolor="#EAEAEA"> <tr> <th>標題1</th> <th>標題2</th> <th>標題3</th> <th>標題4</th> </tr> <tr> <td>數值11</td> <td>數值12</td> <td>數值13</td> <td>數值14</td> </tr> <tr> <td>數值21</td> <td>數值22</td> <td>數值23</td> <td>數值24</td> </tr> <tr> <td>數值31</td> <td>數值32</td> <td>數值33</td> <td>數值34</td> </tr> </table> </body> </html>