我試圖做出一系列Web表單中的複選框,將張貼的不是「真」或「假」到下一個PHP頁面,這取決於它們是否被選中。我決定每個複選框(值=「true」),我會有一個隱藏的複選框(值=「假」),將永遠是相反的(當複選框被選中時,隱藏複選框未選中等)。我正在使用jQuery去做這個。都張貼選中和未選中的複選框
「TD」的元素數是未知的(以下簡稱「TD」可以被克隆的使用按鈕,提交多個值無限次)。爲了測試目的,我將警報添加到了jQuery中。
當我加入了jQuery代碼和隱藏複選框,爲我的源代碼(我把它用於測試目的可見),該代碼將無法工作,我所有的網頁上其他的jQuery停止工作!
jQuery代碼:
$(document).ready(function(){
/***post all 'required' checkboxes instead of just checked ones***/
$(".required").click(function(event){
event.preventDefault();
alert("test");
nextIndex = this.index() + 1;
alert(nextIndex);
$(".required:eq(nextIndex)").attr("checked", !.required:eq(nextIndex).attr("checked"));
});
});
HTML:
<td>
<input type="checkbox" class="required" name="required[]" value="true">
<input type="checkbox" class="required" name="required[]" value="false" style="display: none;" checked>
</td>
這聽起來像一個工作,更適合比複選框單選按鈕。 – lbstr 2012-07-25 19:34:45