我有一個函數,它遍歷一個表並檢查<td>
中的一些複選框,現在可以多次執行這些複選框,其中選擇的複選框不同。但我的問題是,如果我在一個單一實例執行兩次步,然後選擇工作不正常,該表是jQuery複選框 - 多次迭代不工作
<div>
<table> </table>
</div>
代碼中的複選框
// global
var selectedId =""
function populate(Id){
if(selectedId != Id){
selectedId = Id;
// first uncheck previous selection if any
// selective is the class of check box <td>
// <td class="selective"><input type="checkbox" name="packId"
// value="${pack.packId}"></td>
$('.selective input:checkbox').each(function() {
var prevCheckedVal = (this.checked ? $(this).val() :"");
if(prevCheckedVal != ""){
$(this).find("input[type=checkbox]").attr("checked", false);
}
});
// now select check boxes for present selection
$("tr.allVPClass").each(function() {
$this = $(this)
var catId = $this.find("input.IdInVpClass").val();
if(selectedId == catId){
$(this).find("input[type=checkbox]").attr("checked", true);
}
});
}
// open the dialoge
$("#dialog-form").dialog("open");
}
填充這個表在多個div。如果我打開然後單獨DIV其工作,但不選擇/檢查的任何複選框,如果我打開一個相同的div兩次
不清楚你想用你的代碼完成什麼,也應該解釋一些你正在遇到的問題,你是什麼意思「打開單獨的div」? –