在做微信的开发中,发现jquery的delegate绑定的事件监听无响应的解决办法。
前端的小朋友将原来 以下结构的代码
<a href="ssss">
<p>sssss</p>
<p>dddddd</p><div class="aritcle_card flexRow">
<div class="artcardd flexRow">
<a class="aritcle_card_img" href="/ai/2169" title="摩笔天书"><img
src="https://img.php.cn/upload/ai_manual/000/000/000/175680363012129.png" alt="摩笔天书" onerror="this.onerror='';this.src='/static/lhimages/moren/morentu.png'" ></a>
<div class="aritcle_card_info flexColumn">
<a href="/ai/2169" title="摩笔天书">摩笔天书</a>
<p>摩笔天书AI绘本创作平台</p>
</div>
<a href="/ai/2169" title="摩笔天书" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span> </a>
</div>
</div>
</a>改成了
<div data-href="ssss"> <p>ssssss</p> <p>dddddd</p> </div>
因为涉及到一些异步加载的内容,所以使用如下代码来实现 a 标签的功能
$(document).delegate('[data-href]', 'click', function () {
if ($(this).data('href')) {
location.href = $(this).data('href');
}
});
在PC浏览器上没有出现任何问题,当由iPhone 6 自带的浏览器打开的时候却直接失效了。
最终在stackoverflow上找到了解决方案,现记录如下:
On iOS there is no event bubbling without a cursor style. So in your CSS you need to add cursor: pointer; to the element.
添加CSS内容
*[data-href]{cursor: pointer;
}









