JQuery event binding on () and pop-up window implementation code, jquery pop-up window

Source: Internet
Author: User

JQuery event binding on () and pop-up window implementation code, jquery pop-up window

There are usually pop-up windows on the page. Some pop-up windows are dynamically generated, and some are hidden at the bottom of the page. For dynamically generated pop-up windows, if you want to listen to the pop-up events, you can use jQuery's event binding on () method.

The pop-up window is dynamically generated by js. It is displayed 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.

The a label is:

Copy codeThe Code is as follows:
<A style = "display:" title = "use" target = "_ blank" gid = "167" href = "http://act.vip. ***. com/vip/2016/51 dps/# gamelist "class =" co_vip tdu "> use now </a>

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

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

In fact, two events bound to the tag are bound here. When the link is a url, the default behavior is blocked, and the pop-up window closing method is called to jump to the link, that is, the anchor.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.