列表框
<div class="block" id="psi_wh_allocation_m"><table id="result" class="list auto hover fixed" style="width:100%;border-collapse:collapse"><thead><tr><%--<th></th>--%><%--<th><h:checkbox indexed="true" property="SELECTALL" onclick="selectAll(this)" /></th>--%><th><input type="checkbox" id="selectAllCheckbox" onclick="selectAll(this)"></th><th><b:message key="KA0020.G02015.MODEL.SECTION" /></th><th><b:message key="KA0020.G02015.MODEL.BP_GROUP" /></th><th><b:message key="KA0020.G02015.MODEL.PRODUCT_GROUP" /></th><th><b:message key="KA0020.G02015.MODEL.PRODUCT_CATEGORY" /></th><th><b:message key="KA0020.G02015.MODEL.AMS_MODEL" /></th></tr></thead><l:iterate id="PSI_WH_ALLOCATION_M" property="PSI_WH_ALLOCATION_M" indexId="index"><h:tbody><tr><%--<td><h:checkbox name="selectItem" indexed="true" property="FLAG" /></td>--%><td><input name="selectItem" property="FLAG" type="checkbox" class="rowCheckbox"></td><td><b:write name="PSI_WH_ALLOCATION_M" property="SECTION" /></td><td><b:write name="PSI_WH_ALLOCATION_M" property="BP_GROUP" /></td><td><b:write name="PSI_WH_ALLOCATION_M" property="product_group" /></td><td><b:write name="PSI_WH_ALLOCATION_M" property="product_category" /></td><td><b:write name="PSI_WH_ALLOCATION_M" property="ams_model" /></td><%--隱藏列--%><td style="width:0px;display: none;"><h:hidden name="PSI_WH_ALLOCATION_M" indexed="true" property="inventory_item_id" /><%--<b:write name="PSI_WH_ALLOCATION_M" property="inventory_item_id" />--%></td></tr></h:tbody></l:iterate></table></div><div class="mdui-col"><m:right><button type="button"class="face-form-button btnStyle mdui-color-blue-a700"onclick="savePsi_wh_allocation_m()"><b:message key="KA0020.G02015.MODEL.ADD" /></button><button type="button"class="face-form-button btnStyle mdui-color-blue-a700"onclick="del(frmMain)"><b:message key="KA0020.G02015.MODEL.DELETE" /></button></m:right></div>
獲取隱藏值js代碼
function del(frmMain) {debugger//獲取所有tr的數據var table = $("#psi_wh_allocation_m").find("tbody");var myck= document.getElementsByName("selectItem");var num = $("#psi_wh_allocation_m").find("tbody").length;var array = [];for (var a=0;a<num;a++){if (myck[a].checked){var tr = table[a].rows[0].cells;// 遍歷當前 tr 內的所有 td 元素let row = {};row['section'] = tr[1].textContent;row['bp_group'] = tr[2].textContent;row['product_group'] = tr[3].textContent;row['product_category'] = tr[4].textContent;debugger /*刪除有問題 取型號id*/// row['inventory_item_id'] = tr[5].textContent;//獲取隱藏列的值row['inventory_item_id'] = tr[6].querySelector('input').value;array.push(row);}}f.doAjaxResult('allocation.G02015@del', {data: JSON.stringify(array),}, function (res) {if (res.success) {f.doPost(frmMain, 'allocation.G02015@init', true);}else{res.message && alert(res.message);}});
}
其實項目中的 h:hidden 標簽
等同于 input 標簽
復選框js代碼
function selectAll(checkbox) {debuggerif (checkbox.checked == true) {//選中,則將下面表格中信息全部選中存入臨時表中var tableRows = document.getElementById("result").rows.length - 1; // 獲取表格的行數for (var i = 0; i < tableRows; i++) {debuggerif(!document.getElementsByName('selectItem')[i].checked){//判斷表格中checked是否已被選中,若沒有被選中在將數據加入臨時表(已經選中的信息不會再加入臨時表)document.getElementsByName('selectItem')[i].checked=true;//將選中的checkbox勾選上}}} else {//取消選中,則將下面表格中的全部信息從臨時表中刪除var tableRows = document.getElementById("result").rows.length - 1; // 獲取表格的行數for (var i = 0; i < tableRows; i++) {document.getElementsByName('selectItem')[i].checked=false;}}
}