1.要求如下
2.html源码
<div class="btn"> <button type="button" onclick="getYuan()">获取</button> </div> <div class="forms"> <table> <tbody> <tr id="0" class="R1"> <td id="_i_" style="text-align:center;width:20px;">1</td> <td style="text-align:center;width:20px;"> <span> <input type="hidden" name="_s_omorderdeliverheaderv.list" value="0"> <input type="checkbox"> </span> </td> <td style="width:50px;"><a href="../om/omorderdeliverlinesv.do?m=s&omorderdeliverheaderv.form.header_id=123862">查看</a> </td> <td style="width:50px;"><a href="../om/omorderdeliverlinesv.do?m=e&omorderdeliverheaderv.form.header_id=123862">修改</a> </td> <td style="width:125px;">LL202307070017<input type="hidden" name="omorderdeliverheaderv.list.deliver_code" value="LL202307070017"></td> <td style="width:50px;">已发货<input type="hidden" name="omorderdeliverheaderv.list.status" value="2"> </td> <td>0100527<input type="hidden" name="omorderdeliverheaderv.list.vendor_code" value="0100527"></td> <td>YH22890</td> <td>2023-07-07 00:00:00<input type="hidden" name="omorderdeliverheaderv.list.deliver_date" value="2023-07-07 00:00:00"></td> <td><input type="hidden" name="omorderdeliverheaderv.list.receive_date" value=""><input type="hidden" name="omorderdeliverheaderv.list.header_id" value="123862"><input type="hidden" name="omorderdeliverheaderv.list.vendor_id" value="7425"><input type="hidden" name="omorderdeliverheaderv.list.sheet_type_id" value="2045"><input type="hidden" name="omorderdeliverheaderv.list.address" value="*"><input type="hidden" name="omorderdeliverheaderv.list." value="0"><input type="hidden" name="omorderdeliverheaderv.list.." value="0"><input type="hidden" name="omorderdeliverheaderv.list.header_id.k" value="123862"></td> </tr> <br> <tr id="1" class="R2"> <td id="_i_" style="text-align:center;width:20px;">2</td> <td style="text-align:center;width:20px;"><span><input type="hidden" name="_s_omorderdeliverheaderv.list" value="0"><input type="checkbox"></span></td> <td style="width:50px;"><a href="../om/omorderdeliverlinesv.do?m=s&omorderdeliverheaderv.form.header_id=123214">查看</a> </td> <td style="width:50px;"><a href="../om/omorderdeliverlinesv.do?m=e&omorderdeliverheaderv.form.header_id=123214">修改</a> </td> <td style="width:125px;">LL202307030015<input type="hidden" name="omorderdeliverheaderv.list.deliver_code" value="LL202307030015"></td> <td style="width:50px;">已发货<input type="hidden" name="omorderdeliverheaderv.list.status" value="2"> </td> <td>0100527<input type="hidden" name="omorderdeliverheaderv.list.vendor_code" value="0100527"></td> <td>YH20976</td> <td>2023-07-03 00:00:00<input type="hidden" name="omorderdeliverheaderv.list.deliver_date" value="2023-07-03 00:00:00"></td> <td><input type="hidden" name="omorderdeliverheaderv.list.receive_date" value=""><input type="hidden" name="omorderdeliverheaderv.list.header_id" value="123214"><input type="hidden" name="omorderdeliverheaderv.list.vendor_id" value="7425"><input type="hidden" name="omorderdeliverheaderv.list.sheet_type_id" value="2045"><input type="hidden" name="omorderdeliverheaderv.list.address" value="*"><input type="hidden" name="omorderdeliverheaderv.list." value="0"><input type="hidden" name="omorderdeliverheaderv.list.." value="0"><input type="hidden" name="omorderdeliverheaderv.list.header_id.k" value="123214"></td> </tr> <br> <tr id="2" class="R3"> <td id="_i_" style="text-align:center;width:20px;">3</td> <td style="text-align:center;width:20px;"><span><input type="hidden" name="_s_omorderdeliverheaderv.list" value="0"><input type="checkbox"></span></td> <td style="width:50px;"><a href="../om/omorderdeliverlinesv.do?m=s&omorderdeliverheaderv.form.header_id=123214">查看</a> </td> <td style="width:50px;"><a href="../om/omorderdeliverlinesv.do?m=e&omorderdeliverheaderv.form.header_id=123214">修改</a> </td> <td style="width:125px;">LL202307030015<input type="hidden" name="omorderdeliverheaderv.list.deliver_code" value="LL202307030015"></td> <td style="width:50px;">已发货<input type="hidden" name="omorderdeliverheaderv.list.status" value="2"> </td> <td>0100527<input type="hidden" name="omorderdeliverheaderv.list.vendor_code" value="0100527"></td> <td>YH20976</td> <td>2023-07-03 00:00:00<input type="hidden" name="omorderdeliverheaderv.list.deliver_date" value="2023-07-03 00:00:00"></td> <td><input type="hidden" name="omorderdeliverheaderv.list.receive_date" value=""><input type="hidden" name="omorderdeliverheaderv.list.header_id" value="123214"><input type="hidden" name="omorderdeliverheaderv.list.vendor_id" value="7425"><input type="hidden" name="omorderdeliverheaderv.list.sheet_type_id" value="2045"><input type="hidden" name="omorderdeliverheaderv.list.address" value="*"><input type="hidden" name="omorderdeliverheaderv.list." value="0"><input type="hidden" name="omorderdeliverheaderv.list.." value="0"><input type="hidden" name="omorderdeliverheaderv.list.header_id.k" value="123214"></td> </tr> </tbody> </table> </div>
3.JavaScript代码
function getYuan() { //获取所有已选中元素序列 var spans = document.querySelectorAll('input[type="checkbox"]:checked'); var str = "" //遍历元素序列 for (var i = 0; i < spans.length; i++) { //获取父节点 var s = spans[i].parentNode; //获取最近的祖先元素 tr var trElement = s.closest('tr'); //是否获取到tr if (trElement) { //获取当前tr下面所有td元素 var tdElements = trElement.querySelectorAll('td'); //遍历td元素 for(var j=0;j<tdElements.length;j++) { //获取特定元素 var inputElement=tdElements[j].querySelector("input[name='omorderdeliverheaderv.list.header_id']") if (inputElement) { var value = inputElement.value; //赋值 if (str == "") { str = str + value } else { str = str + "," + value } } } } } //显示元素的value alert(str) }
以上采用的是循环遍历的方式实现
标签:00,checkbox,checked,07,元素,tr,获取,var From: https://www.cnblogs.com/goodprintf/p/17549625.html