4

我想在选中 html 复选框时弹出一个 jQuery 对话框。我正在使用以下代码。但它不起作用。

$(document).ready(function () {
        $('#chkBoxHelp').click(function () {
            if ($(this).is(':checked')) {
                $("#txtAge").dialog();
            }
        });
    });

html如下:

<input type="checkbox" id="chkBoxHelp"/>
<div id="txtAge" style="display: none;">Age is something</div>

请帮我。

我还想在弹出窗口关闭时取消选中复选框。复选框位于 jQuery 弹出框中。我需要在选中的复选框上打开另一个弹出窗口。

提前致谢。

4

2 回答 2

3

你可以使用openandclose方法和close事件。

代码:

$(document).ready(function () {
    $('#chkBoxHelp').click(function () {
        if ($(this).is(':checked')) {
            $("#txtAge").dialog({
                close: function () {
                    $('#chkBoxHelp').prop('checked', false);
                }
            });
        } else {
            $("#txtAge").dialog('close');
        }
    });
});

演示:http: //jsfiddle.net/IrvinDominin/V9zMx/

于 2013-10-04T12:54:42.330 回答
2

试试这个,如果再次单击复选框,也会关闭。

$(document).ready(function () {
    var the_checkbox = $('#chkBoxHelp');
    the_checkbox.click(function () {
        if ($(this).is(':checked')) {
            $("#txtAge").dialog({
                close: function () {
                    the_checkbox.prop('checked', false);
                }
            });
        } else {
            $("#txtAge").dialog('close');
        }
    });
});

演示在这里

于 2013-10-04T12:51:49.167 回答