Home >Web Front-end >JS Tutorial >jQuery event binding on() and pop-up window implementation code_jquery
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:
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; } }); }
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. .