JS代码不适用于移动设备

时间:2016-01-07 14:14:56

标签: javascript mobile

我有以下代码

$('.checkbox.radio-info input[type="checkbox"]').change(function() {
    if ($(this).parent().parent().find('input[type="checkbox"]:checked').length > 1)
    {
        $(".checkbox.radio-info input[type='checkbox'").prop('checked', false);
        $(this).prop('checked', true);
    }
});

这在桌面上按预期工作,但是,在我的iPhone(iOS 9,Chrome)上它不起作用。当我检查另一个时,它不会取消选中该复选框。

此代码中是否有与设备相关的内容?

2 个答案:

答案 0 :(得分:1)

好像你错过了一行中的“]”: $(".checkbox.radio-info input[type='checkbox'").attr('checked', false);

也许你的桌面浏览器更宽容了?

如果这没有帮助,请分享您的HTML。

答案 1 :(得分:0)

在代码中尝试attr而不是prop。

$('.checkbox.radio-info input[type="checkbox"]').change(function() {
if ($(this).parent().parent().find('input[type="checkbox"]:checked').length > 1)
{
    $(".checkbox.radio-info input[type='checkbox'").attr('checked', false);
    $(this).attr('checked', true);
}});
相关问题