0

我有以下脚本

$(document).ready(function(){
    var link = $('.menu > ul > li');
    $(link).click (function(e) {
        $(this).addClass('active').siblings().removeClass('active');
        var a = $(e.target).attr('href');
        if(a == '#'){
            e.preventDefault();
            };
        });
});

单击顶层后,将显示一个子级菜单。html结构的一个例子是;

 <li><a href="#">mortgages</a>
                <!-- SUBMENU START -->
                <ul>
                    <li><a href="first-time-buyers.php">first time buyers</a></li>
                    <li><a href="moving-home.php">moving home</a></li>
                    <li><a href="remortgaging.php">remortgaging</a></li>
                    <li><a href="buy-to-let.php">buy to let</a></li>
                    <li><a href="self-build.php">self build</a></li>
                    <li><a href="commercial.php">commercial</a></li>
                    <li><a href="mortgage-search.php">mortgage search</a></li>
                    <li><a href="http://www.quote-conveyancing.co.uk/GetQuote.aspx?int=47495349">conveyancing quote</a></li>
                </ul>
                <!-- SUBMENU END -->
            </li>

这在台式机上效果很好,但在 iPhone/iPad 等上它不起作用。在网上搜索后,我意识到这是因为这些设备将第一次按下视为悬停。

但问题是,我尝试了一些常见的建议,但没有运气。我试过了;

添加 cursor:pointer 指向 css 并在单击后尝试 touchstart。

还有其他人可以建议尝试吗?

编辑: 认为我越来越近了。我已经稍微改变了脚本(上面编辑过),现在如果你按住菜单项直到 iPhone 弹出询问你想如何打开页面的消息,子菜单下面就会出现。然后,一旦出现,单击顶部菜单即可无缝运行。

有没有人知道为什么初始点击不能正常工作?

4

1 回答 1

0

All mobiles doesn't have a click event. You have to use jquery mobile or something like this. On mobiles is using touch instead of click. There are a lot of libraries that where find that is mobile than transform click to touch. You can do it by yourself. Just find if exists touch event and than use touch

Good luck

于 2014-05-22T19:43:36.207 回答