Javascript 如何在Jquery UI对话框中检查复选框值

Javascript 如何在Jquery UI对话框中检查复选框值,javascript,jquery,html,jquery-ui,Javascript,Jquery,Html,Jquery Ui,我试图在JQuery UI对话框中调用changeShowTips()方法, 但是,该方法始终返回“未选中!!!!” 有什么问题吗 <div id="dialog-tip"> <div> <input type="checkbox" name="showTips" value="showTips" checked="checked" onclick="changeShowTips();"/>Show tips o

我试图在JQuery UI对话框中调用changeShowTips()方法, 但是,该方法始终返回“未选中!!!!”

有什么问题吗

    <div id="dialog-tip">
        <div>
            <input type="checkbox" name="showTips" value="showTips" checked="checked" onclick="changeShowTips();"/>Show tips on start up
        </div>
    </div>

    <script type="text/javascript">
        $(document).ready(function () {
            showTips()
        });


        function showTips() {
            $("#dialog-tip").dialog({
                height: 520,
                width: 515,
                modal: true,
            }).parents('.ui-dialog:eq(0)').wrap('<div class="black-tie"></div>');             
        }

        function changeShowTips() {
            if (showTips.checked == true) {
                alert('checked!!!');
            }
            else {
                alert('NOT checked!!!');
            }
        }

    </script>

展示启动技巧
$(文档).ready(函数(){
showTips()
});
函数showTips(){
$(“#对话框提示”)。对话框({
身高:520,
宽度:515,
莫代尔:是的,
}).parents('.ui对话框:eq(0')).wrap('');
}
函数changeShowTips(){
如果(showTips.checked==true){
警报(‘已检查!!!’);
}
否则{
警报('未选中!!!');
}
}
试试这个

给输入一个showTips的id和名称,然后

    function changeShowTips() {
        if ($('#showTips').is(':checked')) {
            alert('checked!!!');
        }
        else {
            alert('NOT checked!!!');
        }
    }
试试这个

给输入一个showTips的id和名称,然后

    function changeShowTips() {
        if ($('#showTips').is(':checked')) {
            alert('checked!!!');
        }
        else {
            alert('NOT checked!!!');
        }
    }

你有一些乱七八糟的jQuery

 <div id="dialog-tip">
    <div>
        <input type="checkbox" name="showTips" value="showTips" checked="checked"/>Show tips on start up
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        showTips()

        $('input', '#dialog-tip').click(changeShowTips()); // do not have inline js, bind it here
    });


    function showTips() {
        $("#dialog-tip").dialog({
            height: 520,
            width: 515,
            modal: true,
        }).parents('.ui-dialog').eq(0).wrap('<div class="black-tie"></div>');       
        // it is faster for sizzle to use a standard css selector to modify the jquery object and then use a jquery specific selector 'eq' separately
        // instead of combining css/jquery selectors in one statement      
    }

    function changeShowTips() {
        if ($('input', '#dialog-tip').is(':checked')) { // there is jQuery for this - you should also compare and not assign
            alert('checked!!!');
        }
        else {
            alert('NOT checked!!!');
        }
    }

</script>

展示启动技巧
$(文档).ready(函数(){
showTips()
$('input','#dialog tip')。单击(changeShowTips());//没有内联js,请将其绑定到此处
});
函数showTips(){
$(“#对话框提示”)。对话框({
身高:520,
宽度:515,
莫代尔:是的,
}).parents('.ui对话框').eq(0).wrap('');
//sizzle使用标准css选择器修改jquery对象,然后单独使用特定于jquery的选择器“eq”,速度更快
//而不是在一条语句中组合css/jquery选择器
}
函数changeShowTips(){
如果($('input','#dialog tip').is(':checked'){//有jQuery用于此-您还应该进行比较,而不是赋值
警报(‘已检查!!!’);
}
否则{
警报('未选中!!!');
}
}

您的jQuery有些混乱

 <div id="dialog-tip">
    <div>
        <input type="checkbox" name="showTips" value="showTips" checked="checked"/>Show tips on start up
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        showTips()

        $('input', '#dialog-tip').click(changeShowTips()); // do not have inline js, bind it here
    });


    function showTips() {
        $("#dialog-tip").dialog({
            height: 520,
            width: 515,
            modal: true,
        }).parents('.ui-dialog').eq(0).wrap('<div class="black-tie"></div>');       
        // it is faster for sizzle to use a standard css selector to modify the jquery object and then use a jquery specific selector 'eq' separately
        // instead of combining css/jquery selectors in one statement      
    }

    function changeShowTips() {
        if ($('input', '#dialog-tip').is(':checked')) { // there is jQuery for this - you should also compare and not assign
            alert('checked!!!');
        }
        else {
            alert('NOT checked!!!');
        }
    }

</script>

展示启动技巧
$(文档).ready(函数(){
showTips()
$('input','#dialog tip')。单击(changeShowTips());//没有内联js,请将其绑定到此处
});
函数showTips(){
$(“#对话框提示”)。对话框({
身高:520,
宽度:515,
莫代尔:是的,
}).parents('.ui对话框').eq(0).wrap('');
//sizzle使用标准css选择器修改jquery对象,然后单独使用特定于jquery的选择器“eq”,速度更快
//而不是在一条语句中组合css/jquery选择器
}
函数changeShowTips(){
如果($('input','#dialog tip').is(':checked'){//有jQuery用于此-您还应该进行比较,而不是赋值
警报(‘已检查!!!’);
}
否则{
警报('未选中!!!');
}
}

从语法角度看,您似乎试图使用vanilla JS而不是jQuery来选中复选框

jQuery选择器类似于$([…]),通常用于选择类$(“.someclass”)或ID$(“#someid”)。如果您确实不想为输入字段提供ID,请查看文档:


然后,您可以使用$([…]).prop(“checked”)来确定它是否被选中。

从语法角度看,您似乎在尝试使用vanilla JS而不是jQuery来选中复选框

jQuery选择器类似于$([…]),通常用于选择类$(“.someclass”)或ID$(“#someid”)。如果您确实不想为输入字段提供ID,请查看文档:


然后您可以使用$([…]).prop(“checked”)来确定它是否被选中。

这是因为在代码中,showTips指的是您的函数,而不是目标元素

<input type="checkbox" 
       name="showTips" 
       value="showTips" 
       checked="checked" 
       onclick="changeShowTips(this);"
/> Show tips on start up

这是因为在代码中,showTips指的是您的函数,而不是目标元素

<input type="checkbox" 
       name="showTips" 
       value="showTips" 
       checked="checked" 
       onclick="changeShowTips(this);"
/> Show tips on start up
if(showTips.checked=true)
应该是
if(showTips.checked)
,但是
showTips
从哪里来?
if(showTips.checked=true)
应该是
if(showTips.checked)
,但是
showTips
从哪里来?