1、問題描述
點擊 table 中的某行 tr,獲取該 tr 下的第一個 td 標簽下的< input type="hidden" value="92"/>(隱藏域)的 value 值,即獲取 92。
HTML代碼
1 <table class="layui-table" id="alertTable" style="margin: 0 auto; width: 100%;"> 2 <thead> 3 <tr> 4 <th>日期</th> 5 <th>經度</th> 6 <th>緯度</th> 7 <th>距離</th> 8 </tr> 9 </thead> 10 <tbody> 11 <tr class="alertChart"> 12 <td> 13 <input type="hidden" value="92" /> 2017-06-01 </td> 14 <td>110.23568</td> 15 <td>125.23564</td> 16 <td>25.2m</td> 17 </tr> 18 </tbody> 19 </table>
2、解決方案
js代碼(jQuery操作)
1 $('.alertChart').dblclick(function(){ 2 alert( $(this).children('td').eq(0).children('input').val() ) ; 3 });
正確輸出

3、筆記
① parent和parents的區別
parent()是找當前元素的第一個父節點,不管匹不匹配都不繼續往下找 parents()是找當前元素的所有父節點
② child和childern的區別
child()是找當前元素的第一個子節點,不管匹不匹配都不繼續往下找 childern()是找當前元素的所有子節點
