简体   繁体   English

jQuery函数和页面重新加载问题(也许)

[英]jQuery function and Page Reload issue (maybe)

I have this code (accepted solution). 我有代码(可接受的解决方案)。 This code snipped loads from a js file. 这段代码从js文件中载入。 When I put a breakpoint at this function, I see that this function getting called when the page (that includes it) is loaded. 当我在此函数上设置断点时,我看到该函数在页面(包括它)加载时被调用。

After the initial page load, when I choose an option in this page, that anchor element is reloaded (Ajax) exactly same (js file does not reload) as part of the piece of data. 在初始页面加载之后,当我在该页面中选择一个选项时,该锚元素将作为数据的一部分完全重新加载(Ajax)(不重新加载js文件)。 However, now when I click on anchor link, it does not fire / open the outlook window. 但是,现在当我单击锚链接时,它不会触发/打开Outlook窗口。

Is it something about jQuery functionality that I am mis reading/using? 我误读/使用的有关jQuery功能的东西吗? How do I resolve this? 我该如何解决?

If the element is reloaded you'll need to rebind the click event to it. 如果重新加载了元素,则需要将click事件重新绑定到该元素。

Alternatively to the way you are doing it you could bind to the window/body and just specify the id as the selector like this: 除了执行此操作以外,还可以将其绑定到窗口/主体,然后仅将id指定为选择器,如下所示:

$('body').on('click', '#emailLink', function (event) {
    // your code here...
});

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

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