为什么这个JQuery代码在移动设备上中断?

时间:2015-03-07 12:01:42

标签: javascript jquery html ios mobile

我有以下代码适用于所有桌面浏览器:

JQuery的:

$('.select-one-style').on('click',function(){
    $('.select-one-style').removeClass('active');
    $(this).toggleClass('active');
    var radioBtn = $(this).children('input[type=radio]');
    radioBtn.prop('checked', true);
})

HTML:

            <div class="choice-box select-one-style">
                <img src="/static/shipment/images/style-wall-street.jpg" alt="Wall Street" />
                <p>Wall Street</p>
                <input type="radio" name="look-type" value="wall-street" />
            </div>
            <div class="choice-box select-one-style">
                <img src="/static/shipment/images/style-classic.jpg" alt="Classic" />
                <p>Classic</p>
                <input type="radio" name="look-type" value="classic" />
            </div>
            <div class="choice-box select-one-style">
                <img src="/static/shipment/images/style-hipster.jpg" alt="Hipster" />
                <p>Hipster</p>
                <input type="radio" name="look-type" value="hipster" />
            </div>
            <div class="choice-box select-one-style">
                <img src="/static/shipment/images/style-preppy.jpg" alt="Preppy" />
                <p>Preppy</p>
                <input type="radio" name="look-type" value="preppy" />
            </div>

但是,每当我在iOS上使用移动浏览器(包括Safari和Chrome)访问我的网站时(尚未测试Android),当我点击图像/输入时,不会检查单选按钮(尽管CSS效果会发生这样我知道触摸事件被注册为点击)。

有人知道为什么这段代码会在移动设备上中断?非常感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

由于ios 8中的300 ms延迟(分接延迟),可能会发生这种情况。 您可以尝试引入此元标记以避免延迟(从各种来源读取)

<meta name="viewport" content="width=device-width, user-scalable=no">

我希望它至少适用于ios上的mobile-chrome浏览器。试试吧

相关问题