我有
<input type="checkbox" id="checkbox1" /> <br />
<input type="text" id="textbox1" />
和
$(document).ready(function() {
//set initial state.
$('#textbox1').val($(this).is(':checked'));
$('#checkbox1').change(function() {
$('#textbox1').val($(this).is(':checked'));
});
$('#checkbox1').click(function() {
if (!$(this).is(':checked')) {
return confirm("Are you sure?");
}
});
});
JSFIDDLE链接
这里更改的事件用复选框状态更新文本框的值。我使用click事件来确认操作取消选中。如果用户选择取消,则复选标记将被恢复,但更改甚至会在确认事件处于不一致状态之前触发(当复选框被选中时,文本框为false)。我怎样才能处理取消和保持文本框的值与检查状态一致?
相似问题