【发布时间】:2012-05-02 06:36:17
【问题描述】:
我有一个带有复选框的模态 jQuery UI 对话框:
$dialog = $('<div id="formContainer"></div>')
.html('<div>some text</div><input id="accept_cb" type="checkbox" checked="checked"/> Uncheck this box to disable.<br />')
.dialog({
autoOpen: false,
title: 'Title ',
modal: true,
buttons: {
"Close": function() {
checkboxHandler();
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
});
function checkboxHandler(){
if ($('#accept_cb').is(':checked'))
{
alert('checked');
}else{
alert('not checked');
}
}
当我第一次打开对话框时,一切正常,并提醒正确的检查状态。但是当我第二次返回时,无论是第一次,状态都保持“已检查”或“未检查”。我需要改变什么?
我也尝试了().attr 和().prop,结果相同。
【问题讨论】:
-
缺少引用:.html(一些文本
标签: jquery jquery-ui checkbox dialog modal-dialog