jquery点击不在ipad / iphone上工作

时间:2014-02-04 14:32:03

标签: javascript jquery iphone ipad

我有一个链接下拉列表,我在页面加载时转换为选择框。这适用于台式机/笔记本电脑,但它不适用于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();

            });

        });

    });
    });

点击功能是不是可以在所有设备上运行?

艾哈迈尔

1 个答案:

答案 0 :(得分:2)

使用touchstart

 $('ul.selectdropdown >li a').on('click touchstart',function(){

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

            window.open(this.href);

        }
 });