2

这似乎有一个非常明显的答案,但是一旦我添加了 Jquery Mobile,我就无法获得一个简单的复选框来取消选中 JQuery。

这是一些非常简单的代码作为说明:

<html>
<head>
    <title>Untitled</title>

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

<script>

    jQuery(function () {

        jQuery('#a').change(function () {

            if (jQuery(this).is(':checked')) {
                jQuery('#b').removeAttr('checked');
            }

        });

        jQuery('#b').change(function () {

            if (jQuery(this).is(':checked')) {
                jQuery('#a').removeAttr('checked');


            }

        });

    });

</script>
</head>

<body>

<input type="checkbox" id="a"><label for="a">AAAA</label>

<input type="checkbox" id="b"><label for="b">BBBB</label>

</body>
</html>

这是一段简单的代码。当复选框'A'被选中时,它应该取消选中复选框'B',并且虎钳诗句。但是它没有,并且没有错误写入控制台。

这是使用标准版本的 Jquery & Jquery Mobile,直接链接到他们的网站

如果我通过删除以下几行来删除 Jquery Mobile 元素,那么它可以正常工作

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>

谁能告诉我我哪里出错了,因为这看起来很简单,但我对发生的事情完全不知所措。

非常感谢

4

1 回答 1

3

因为您需要使用.prop然后使用.checkboxradio('refresh').

查看

$('selector').prop('checked', true).checkboxradio('refresh');

取消选中

$('selector').prop('checked', false).checkboxradio('refresh');
于 2013-05-16T05:19:41.030 回答