【问题标题】:Dynamic Drop Down on iPhoneiPhone 上的动态下拉菜单
【发布时间】:2013-08-06 19:26:15
【问题描述】:

我正在尝试在移动设备(更具体地说是 iPhone Safari)上复制以下 Fiddle (http://jsfiddle.net/3UWk2/1/),但它似乎没有正确运行 javascript,有什么建议吗?谢谢!!

这是 js:

<script>
$(document).ready(function() {
    $('#00Ni0000007XPVF').bind('change', function() {
        var elements = $('div.container_drop').children().hide(); // hide all the elements
        var value = $(this).val();

        if (value.length) { // if somethings' selected
            elements.filter('.' + value).show(); // show the ones we want
        }
    }).trigger('change');
});
</script>

【问题讨论】:

    标签: javascript iphone mobile dynamic drop-down-menu


    【解决方案1】:

    您似乎正在使用缓存值。 hide 不返回任何内容。因此,当您尝试再次显示它们时会失败。

    var elements = $('div.container_drop').children().hide();
    

    应该是

    var elements = $('div.container_drop').children();
        elements.hide();
    

    代码

    $(document).ready(function() {
        $('#00Ni0000007XPVF').bind('change', function() {
            // cache the value
            var elements = $('div.container_drop').children(); 
                elements.hide();   // hide all the elements
            var value = $(this).val();
    
            if (value.length) { // if somethings' selected
                elements.filter('.' + value).show(); // show the ones we want
            }
        }).trigger('change');
    });
    

    【讨论】:

    • 此解决方案是否专门针对移动设备?我问是因为我已经在网络上实现了它,并且它在所有浏览器中都可以正常工作。
    猜你喜欢
    • 2013-11-05
    • 1970-01-01
    • 1970-01-01
    • 2018-09-29
    • 2012-08-29
    • 2014-06-16
    相关资源
    最近更新 更多