[英]Jquery Tracking checkbox changed from checked to unchecked or its already unchecked
假設我有四個復選框,格式為Check-a,Check-b,Check-c,Check-d。
已經選中了Check-a和Check-b。我可以使用Jquery來檢查或不選中哪個復選框。
現在我取消選中Check-a。 所以Check-a被檢查了,我已經檢查了這個未經檢查。 所以現在Check-c和Check-d已經取消選中,Check-a沒有被我檢查。我正在尋找一種方法來跟蹤哪些是未選中的,而且之前未選中。
任何人都能告訴我一個方法嗎?
如果您需要一種點擊歷史記錄,為什么不使用額外的字段呢?
HTML:
<form>
<div>
<input type="checkbox" name="fruit" value="o" id="orange" />
<label for="orange">orange</label>
</div>
<div>
<input type="checkbox" name="fruit" value="a" id="apple" />
<label for="apple">apple</label>
</div>
<div>
<input type="text" name="history" id="history" />
</div>
</form>
jquery腳本:
$("input").click(function() {
$("#history").val( $("#history").val() + $(this).val() + ";");
});
你可以把它隱藏起來並評估; 之后分開列表..
假設與@definitelyundefinable相同的HTML,這確實有點相同,但它更清晰,因為它不使用隱藏字段和偽數組(作為隱藏字段中的字符串)
$(function() {
var history = [];
$("input").click(function() {
history.push({
id: this.id,
checked: this.checked
});
});
// If you'd like, you can initialize the array
// with the initial values with the following line
$("input").click();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.