简体   繁体   English

jQuery单击无法在iPad / iPhone上使用

[英]jquery click not working on ipad/iphone

I have a drop down list of links that I am converting into select box upon page load . 我有一个下拉列表链接,这些链接将在页面加载时转换为选择框。 This is working properly on desktop/laptops however it is not working on iphone/ipad. 此功能在台式机/笔记本电脑上正常运行,但在iphone / ipad上无法正常运行。

I am totally new to this so I don't know what may be causing the issue because code seems to work fine and triggers page load on click event. 我对此是完全陌生的,所以我不知道是什么原因引起的,因为代码似乎可以正常工作,并在click事件上触发页面加载。 Here is the code. 这是代码。

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();

            });

        });

    });
    });

Isn't click function suppose to work on all devices? 点击功能不是应该在所有设备上都能工作吗?

Ahmar 艾哈迈尔

use touchstart : 使用touchstart

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

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

            window.open(this.href);

        }
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM