【问题标题】:jquery click not working on ipad/iphonejquery click 在 ipad/iphone 上不起作用
【发布时间】:2014-02-04 14:32:02
【问题描述】:

我有一个链接的下拉列表,我在页面加载时将其转换为选择框。这在台式机/笔记本电脑上正常工作,但在 iphone/ipad 上不起作用。

我对此完全陌生,所以我不知道是什么导致了这个问题,因为代码似乎工作正常,并在点击事件时触发页面加载。这是代码。

jQuery(document).ready(function ($)
{
$('ul.selectdropdown').each(function(){

    var select=$(document.createElement('select')).insertBefore($(this).hide());

    $('>li a', this).each(function(){

        var a=$(this).click(function(){

            if ($(this).attr('target')==='_blank'){

                window.open(this.href);

            }

            else{

                window.location.href=this.href;

            }

        }),

        option=$(document.createElement('option')).appendTo(select).val(this.href).html($(this).html()).click(function(){

                a.click();

            });

        });

    });
    });

点击功能不应该适用于所有设备吗?

艾玛

【问题讨论】:

    标签: javascript jquery iphone ipad


    【解决方案1】:

    使用touchstart:

     $('ul.selectdropdown >li a').on('click touchstart',function(){
    
            if ($(this).attr('target')==='_blank'){
    
                window.open(this.href);
    
            }
     });
    

    【讨论】:

    • 它不起作用问题是这部分这是点击实际需要触发的地方 option=$(document.createElement('option')).appendTo(select).val(this.href ).html($(this).html()).click(function(){ a.click();
    • 任何错误??我看到你有这个stackoverflow.com/questions/21577190/… 也不起作用
    • 它在 iphone/ipad 上不起作用,上面线程中提供的代码也不起作用。自己检查。
    • 对我也不起作用,所有功能都可以在标准浏览器中的点击事件中完美运行
    猜你喜欢
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多