jquery parent 选择器
实例1:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script type="text/javascript" src="/jquery/jquery.js"></script> 5 </head> 6 7 <body> 8 9 <div><p>Hello</p></div> 10 <div class="selected"><p>Hello Again</p></div> 11 12 <script> 13 $("p").parent(".selected").css("background", "yellow"); 14 </script> 15 16 </body> 17 </html>
实例2:
1 <tr onclick="setRowIndex(this);" style='display:none' > 2 <td > 3 <select style="width: 100%;" name="materialName" class="button_ui"> 4 <option value="盘纸">盘纸</option> 5 <option value="水松纸">水松纸</option> 6 </select> 7 </td> 8 <td > 9 <span id="iscorrespond" onclick="swap(this);">√</span> 10 </td> 11 <td > 12 <span id="isbumps" onclick="swap(this);">√</span> 13 </td> 14 <td > 15 <input type="text" name="sendid" value="" style="font-size:12pt;" size="7"/> 16 </td> 17 <td > 18 <input type="text" name="checkid" value="" onclick="" style="font-size:12pt;background-color=#EEEEE7;"size="7" readonly disabled/> 19 </td> 20 <td > 21 <input type="text" name="checktime" value="" onclick="gettime(this)" style="width:160px;font-size:12pt;background-color=#EEEEE7;" size="7" readonly disabled/> 22 </td> 23 <td> 24 <select style="width: 100%;" name="status" class="button_ui" disabled> 25 <option value="0">新增</option> 26 <option value="1">送料完成</option> 27 <option value="2">核对完成</option> 28 </select> 29 </td> 30 <td> 31 <input type="button" value="保存" onclick="save(this);"/> 32 </td> 33 </tr> 34 35 //确定&保存 36 function save(v) 37 { 38 if(!window.confirm("确认保存?")){ return; } 39 //获取本次保存的内容 40 var dv = v; 41 var $v = $(dv); 42 //材料名称 43 var materialName = $v.parent().parent().find("select").val(); 44 alert(materialName); 45 }