jquery event binding on () and the example of a bullet window

Source: Internet
Author: User

The page will often have a window, and some of the window is dynamically generated, and some of the window is hidden at the bottom of the page, for dynamically generated window, if you want to listen to the events of the window, you can use jquery event binding on () method implementation.

As shown in the picture, the window is JS dynamic generation, by clicking on a link popup, pop-up window in the "immediately to use" link clicked, the effect is to close the window, and jump to the anchor point.

This a label is:

Xhtml

<a style= "Display:" title= "immediately to use" target= "_blank" gid= "167" href= "/51dps/#gamelist" class= "Co_vip" TDU "> immediately to use </a>

We want to monitor the click event in the window, but the window itself is dynamically generated, so we have to listen to the body, through on () event binding, when dynamically generated this window, you can monitor the click Method:

function Jump_to_anchor () {
$ ("Body"). On ("click", "Span[name= ' Msgbox_info '] a,. act-pop-table a", function (e) {
link = $ (this). attr (' href ');
if (link = = '/51dps/#gamelist ') {
E.preventdefault ();
Msgexit ();
window.location.href = link;
}
});
}

This is actually a binding of two-a-tag event bindings, both when the link is a URL, blocks the default behavior, and calls the close window method to jump to the link, which is the anchor point.

Example

For example, there are two elements below on the page:

<input type= "button" Name= "addbtn" value= "button Add"/>
<div id= "Test" ></div>

Use the jquery code below to see the difference:

$ (function () {
var a = 1,
$_div = $ (' #test ');
$ (' input[name=addbtn] '). On (' click ', function () {
$_div.append (' <input type= "button" name= "Test ' + A + '" value= "button ' + A + '"/> ');
a++;
});

Even item Click event
$_div.on (' Click ', ' Input[name^=test]:even ', function () {
Alert (' I am a valid on method, can you see me: ' + this.value ');
});

Click events for odd-numbered items are found to be invalid, but live methods are available to support
$ (' input[name^=test]:odd '). On (' click ', function () {
Alert (' I am invalid on method, you cannot see me ');
});

Click events for odd-numbered items are found to be invalid, but live methods are available to support
$ (' input[name^=test]:odd '). Live (' click ', function () {
Alert (' I am the live method, can you see me: ' + this.value ');
});
});

Code is simple, do not put the demo page, if there is nothing to understand, you can leave a message

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.