jquery点击函数
好的,基本上我有这个:
<div id="tabs">
<div id="unique_id" class="tab_link" onclick="changeTab(this);">
<div id="tab_link_image" onclick="closeTab(this);">
<image src="image.jpg" />
</div>
</div>
</div>
现在在 closeTab 函数中,我让它从页面中删除选项卡。在changeTab函数中,我让它根据tab_links id(每个id都是唯一的)切换一个类,该类对于每个tab_link类是活动的还是非活动的。在最后的 closeTab 函数中,我调用 changeTab 函数以使第一个选项卡处于活动状态。当您单击 tab_link 时,一切正常。但是,当您单击 tab_link_image 关闭选项卡时,会出现问题。它会正常关闭选项卡,调用changeTab并将选项卡设置为活动状态,但它还会从原始选项卡的onclick事件中再次触发changeTab函数。有没有办法让单击 tab_link_image 时不触发此操作。希望这是有道理的。
ok so basically I have this:
<div id="tabs">
<div id="unique_id" class="tab_link" onclick="changeTab(this);">
<div id="tab_link_image" onclick="closeTab(this);">
<image src="image.jpg" />
</div>
</div>
</div>
Now in the closeTab function I have it removing the tab from the page. In the changeTab function I have it toggling a class that is either active or notactive foreach of the tab_link classes based on the tab_links id (the id is unique for each one). In the closeTab function at the end I call the changeTab function to make the very first tab active. When you click on a tab_link everything works fine. However, when you click on the the tab_link_image to close the tab there is a problem. It closes the tab fine, calls changeTab and sets the tab to active, but it also fires the changeTab function again from the original tabs onclick event. Is there a way to make this not fire when the tab_link_image is clicked. Hopefully that makes sense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看事件冒泡和正确的事件绑定,我想您会在 jQuery 文档
Take a look at event bubbling, and proper event binding, I think you'll find a lot of good info at the jQuery docs