开发者

<span>s inside <a> don't fire "onclick" event in Chrome

开发者 https://www.devze.com 2023-04-04 09:42 出处:网络
Here is a real puzzler: I have this HTML setup for a custom-styled button: <a href=\"#\" onclick=\"doSomething(); return false;\">

Here is a real puzzler: I have this HTML setup for a custom-styled button:

<a href="#" onclick="doSomething(); return false;">
    <span class="left"></span>
    <span class="label">Aplică modificările</span>
    <span class="right"></span>
</a>

What happens is that sometimes I have to click more than once on the button for the onclick event to be fired. I just start clicking and at one point, the event fires.

This only happens on Chrome (IE9 and FF3.6 also works fine). It seems to be random. Sometimes it works at first click.

Has anyone开发者_运维技巧 encountered this problem? Can you suggest a fix I could try?

Thank you! Matt


The code is fine (Testcase: http://jsfiddle.net/mscSX/).

Summon the Developer console (CTRL + SHIFT + J, ESC to toggle the JavaScript console), and keep clicking. If this test doesn't satisfy you, check whether an extension is causing the error.


I think some additional activity is taking place on your page also, and that is interfering with this event. The fact that it sometimes takes one, sometimes many clicks indicates a time-and-event type situation. Can you post more of your page?

0

精彩评论

暂无评论...
验证码 换一张
取 消