本文共 1122 字,大约阅读时间需要 3 分钟。
开发过程中遇到获取checkbox的选中行的某个值,代码如下。checkbox只能选中一个,但是找了很多方法都无效,所以就根据checkbox的长度进行判断了。有好的方法,希望不吝赐教。
function getCheckBox(ob){ var rowid = $(ob).attr("id") //获取当前行的id console.log("row.id:"+rowid); var len = $("input[name=test]:checked").length; //获取checkbox的选取长度 console.log("len"+len); if(len==1){ var check = $("input[name=test]:checked");//选中的复选框 check.each(function(){// var row = $(this).parent("td").parent("tr");//获取当前行 supplierName = row.find("[name='suName']").html();// 行根据选择器获取当前行的某个值 supplierId = row.find("[name='id']").html(); console.log("suName:"+supplierName); console.log("id:"+supplierId); var xx = "#"+id; $("#mdsProcurementPlanTable tbody "+xx).val(supplierName); }) $("#pageId").data("pageCurrent",1); jp.post("${ctx}/mds/mdsPurchaseSupplier/updateSupplier", {id:id,supplierName:supplierName,supplierId:supplierId},function(data){ if(data.success){ jp.success(data.msg); }else{ js.error(data.msg); } }) $("#myModal").modal('hide'); }else{ alert("只能选择一条"); } }
转载地址:http://tcfoi.baihongyu.com/