Home > Web Front-end > JS Tutorial > jQuery event binding on() and pop-up window implementation code_jquery

jQuery event binding on() and pop-up window implementation code_jquery

WBOY
Release: 2016-05-16 15:03:07
Original
1278 people have browsed it

There are often pop-up windows on the page. Some pop-up windows are dynamically generated, and some pop-up windows are hidden at the bottom of the page. For dynamically generated pop-up windows, if you want to monitor the pop-up window events, you can use jQuery Event binding on() method is implemented.

As shown in the picture, the pop-up window is dynamically generated by js. It pops up by clicking a link. After clicking the "Use Now" link in the pop-up window, the effect is to close the pop-up window and jump to the anchor point.

This a tag is:

Copy code The code is as follows:

We need to monitor the click event in the pop-up window, but the pop-up window itself is dynamically generated, so we need to monitor the body and bind it through the on() event. When the pop-up window is dynamically generated, the click method can be monitored :

function jump_to_anchor() {
  $("body").on("click", "span[name='msgbox_info'] a, .act-pop-table a", function (e) {
    link = $(this).attr('href');
    if (link == 'http://act.vip.***.com/vip/2016/51dps/#gamelist') {
      e.preventDefault();
      msgExit();
      window.location.href = link;
    }
  });
}
Copy after login

This is actually an event binding with two a tags. When the link is a certain URL, the default behavior is blocked, and the pop-up window closing method is called to jump to the link, which is the anchor point. .

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template