简体   繁体   English

javascript click事件不适用于iOS中contenteditable div内的链接

[英]javascript click event isn't working on link inside contenteditable div in iOS

HTML: HTML:

<div id="content" contenteditable="true">
Some text <a href="/">Link</a>
</div>

Javascript: Javascript:

$("#content").find('a').click(function(){
    alert('a clicked');
});

Problem: alert isn't called. 问题:没有调用警报。 It seems that click event isn't called 似乎没有调用click事件

jsfiddle: http://jsfiddle.net/bFtbV/ jsfiddle: http : //jsfiddle.net/bFtbV/

Not enough info here, unless you didn't override the default behavior of the link. 这里没有足够的信息,除非您没有覆盖链接的默认行为。 If that is the case with this code it should work: 如果是这种代码,它应该可以工作:

$("#content").find('a').click(function(e){
    e.preventDefault();
    alert('a clicked');
    return false;
});

If not: 如果不:

  • The problem is somewhere else like js error preventing the script to execute? 问题出在其他地方,例如js错误导致脚本无法执行? What your browser console says? 您的浏览器控制台说什么?
  • Is the link clickable at all, clean the script and put href reference, some address and test it. 链接是否可以单击,请清理脚本并放置href参考,一些地址并对其进行测试。
  • There might be 3th option you are using framework that already overrode the native click event. 您正在使用的框架可能已经覆盖了本地点击事件的第三个选项。

Have you tested it on a pc or mac? 您在PC或Mac上测试过吗? iOS isn't the best place to debug! iOS不是最佳的调试场所! With iOS6 it's even harder unless you have mac with Lion OS X. 借助iOS6,除非您将Mac与Lion OS X结合使用,否则甚至更难。

Test and give us feedback 测试并给我们反馈

Try selecting the a tag directly in the selector: 尝试直接在选择器中选择一个标签:

$("#content a").click(function(){
    alert('a clicked');
});

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

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