简体   繁体   English

在iOS上使用Safari单击时更改链接的CSS

[英]Change CSS of link when clicked with Safari on ios

I have this Javascript on my site with Jquery: 我的网站上有使用Jquery的Javascript:

$("a").on("click", aClicked);

function aClicked(e)
{
    $(this).addClass("clicked");
    // e.preventDefault();
    return true;
}

The css for class "clicked" changes the background color for this link. 类“单击”的css更改此链接的背景颜色。

It works fine on mobile devices with Android/Chrome browser. 它在装有Android / Chrome浏览器的移动设备上可以正常运行。 The color is changed, the link is followed. 更改颜色,然后单击链接。

It does not work with on iOS with Safari or WKWebView. 它不适用于带有Safari或WKWebView的iOS。 It does work with UIWebView. 它可以与UIWebView一起使用。 My current device is iphone6+/ios9.3. 我当前的设备是iphone6 + / ios9.3。

When I uncomment // e.preventDefault(); 当我取消注释// e.preventDefault(); it does work, but the link is not followed of course. 它确实起作用,但是当然不会遵循该链接。 So to me it seems, that safari is too clever and does not render the page when it follows the link anyway? 所以在我看来,Safari浏览器太聪明了,无论如何跟随链接都不会呈现该页面?

I don't want solutions regarding tap-highlight-color or :active or :hover pseudo class for some reasons. 由于某些原因,我不想要有关tap-highlight-color或:active或:hover伪类的解决方案。

How can I fix it? 我该如何解决? Or did I miss something else? 还是我想念其他东西?

我将其与Jquery mobile一起更改为“ tap”而不是“ click”,并且可以正常工作。

$("a").on("tap", aClicked);

Try this work around... add a cursor pointer to the element $('a').css('cursor','pointer'); 尝试解决此问题...向元素$('a').css('cursor','pointer');添加光标指针 or try on focus instead of on click event 或重点关注而不是点击事件

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

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