< a href onClick =“"返回假;">在Safari/iOS中无法使用? [英] <a href onClick="return false;"> not working in Safari/iOS?

查看:40
本文介绍了< a href onClick =“"返回假;">在Safari/iOS中无法使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有以下代码:

I have this code in my page:

<a href onClick="return false;">Press me!</a>

该链接放置在具有有用的onClick事件的范围内.

The link is placed inside a span with a useful onClick event.

现在,在Chrome和Firefox中,它可以完美运行.单击链接,执行有用的事件,每个人都很高兴.在使用默认Safari浏览器的iOS(iPhone和iPad)中,该操作很失败-单击链接后,将重新加载整个页面,并且永远不会执行有用的事件.

Now, in Chrome and Firefox this works perfectly. The link is clicked, the useful event is executed and everybody's happy. In iOS (iPhone and iPad) using the default Safari browser, this fails miserably - after the link is clicked the whole page is reloaded and the useful event is never executed.

我也尝试过

<a href="#" onClick="return false;">Press me!</a>

我认为这是错误的做法.在Chrome和Firefox中,它运行良好,但在iOS的Safari中,它跳回到了页面的开头(但是它DID执行了有用的事件,因此从某种意义上说更好).

Which I understood to be the wrong way of doing this. In Chrome and Firefox it works well, but in iOS' Safari it jumped back to the beginning of the page (but it DID execute the useful event, so in a sense it was better).

我想念什么?

推荐答案

从您的描述看来,这似乎是iOS浏览器JS实现中的错误(也许创建了一个最小的代码来演示它?).

From your description, it seems like a bug in iOS browser JS implementation (maybe create a minimal code to demonstrate it?).

一个简单的解决方法是将< a href ...> 替换为&span style ="cursor:pointer;"> .

A simple workaround would be to replace the <a href...> with <span style="cursor:pointer;">.

这篇关于&lt; a href onClick =“&quot;返回假;&quot;&gt;在Safari/iOS中无法使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆