简体   繁体   English

在jQuery中使用相同的div附加多个点击事件

[英]Attaching multiple click events with same div in Jquery

I have one div and there are two events associated with it first is a click and another a popover trigger which also gets triggered on click . 我有一个div,并且有两个与之关联的事件,第一个是click,另一个是popover触发器,它也会在click上触发。

Now with first click i need to modify the href attribute of the div and second popover event should pick this modified href and opens up a popover with content fetched from href. 现在,首先单击,我需要修改div的href属性,第二个popover事件应选择此修改后的href,并打开一个包含从href获取的内容的弹出窗口。

The problem i am facing (looks liek to me ) is second popover triggers still picks up old value and appears to me that the sequence/order in which i registered the events is not maintained . 我面临的问题(对我来说似乎很客气)是第二个弹出触发器仍旧使用旧值,并且在我看来,我注册事件的顺序/顺序没有得到维护。 How can I solve this problem. 我怎么解决这个问题。

Here is the my code sample: 这是我的代码示例:

retVal = originalURL;

retVal = jQuery('#'+'linkhere').click(getHashPageClick); // thsi function returns a href
(the value is correctly returned )

jQuery('#'+'linkhere').popoverTrigger(retVal); // thsi function opens up a popover with contents fetched from href URL.

but its still picking original URL. 但它仍在选择原始网址。 Can someone help. 有人可以帮忙吗?

call the popovertrigger after you call the gethashpage. 调用gethashpage后,请调用popovertrigger。 That should do the trick. 这应该够了吧。

jQuery('#'+'linkhere').click( function() {
  getHashPageClick();
  popOvertrigger();
})

Remember you can specifcy a function to your click function, so you can do a chain of events there 请记住,您可以为click函数指定一个函数,因此您可以在其中执行一系列事件

The problem is the order the events are firing. 问题在于事件触发的顺序。 There may be a tricky solution using event propagation and bubbling and other fancy things, but there's a simpler solution. 使用事件传播和冒泡以及其他奇特的东西可能有一个棘手的解决方案,但是有一个更简单的解决方案。 Just use mousedown ! 只需使用mousedown

$('#'+'linkhere').mousedown(getHashPageClick);

萤火虫示例

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

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