【发布时间】:2013-06-12 20:17:29
【问题描述】:
我在列表视图中包含以下 HTML sn-p。列表视图中的每个元素都以缩略图开头。
<li>
<a href="javascript:alert("don't want to see this alert);" >
<img src="/images/testimage_thumb.png" onclick="displayImage('/gallery/testimage.jpg');">
<h4>Test Image</h4>
<p>Description of test Image</p>
</a>
</li>
<li>
<a href="javascript:alert("don't want to see this alert either);" >
<img src="/images/testimage2_thumb.png" onclick="displayImage('/gallery/testimage2.jpg');">
<h4>Second Test Image</h4>
<p>Description of the Second Test Image</p>
</a>
</li>
像冠军一样工作(至少在展示方面)。我希望能够让用户单击缩略图以显示更大的图像,而不是触发底层的锚链接(在这种情况下显示警报消息)。
我确定答案在于 preventDefault(),只是不确定如何将 click 事件绑定到允许我访问事件对象的函数。列表视图中将有多个拇指,并且列表是动态生成的以响应另一个事件。我在页面加载时使用 pagebeforeshow() 事件来生成列表。
【问题讨论】:
-
代码取决于您存储路径大img的位置。但这里有一个提示
$(document).on('click', 'li a img', fucntion(e) { e.preventDefualt(); your code here });
标签: jquery jquery-mobile