我在列表视图中包含以下 HTML 片段。列表视图中的每个元素都以缩略图开头。
<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() 事件来生成列表。