简体   繁体   English

jQuery委托不在IE8及更低版本中触发

[英]JQuery delegate not firing in IE8 and lower

I have the following code below where I setup global variables, set elements to these variables and then assign a delegate change event on a dropdown. 我在下面的代码中设置了全局变量,将元素设置为这些变量,然后在下拉列表中分配了一个委托更改事件。

The change event fires in all browsers except IE8 and lower. 在除IE8及更低版本之外的所有浏览器中都会触发change事件。 Not too bothered about IE7 and lower. 不太担心IE7及更低版本。

Any help appreciated? 任何帮助表示赞赏吗?

$(function () {
    initialisePage();
});

function initialisePage() {
    window.portfolioGroupFilters = $("#portfolioGroupFilters");
    window.portfolioGroupsList = $("#portfolioGroupsList");
    window.portfolioGroupAccounts = $("#portfolioGroupAccounts");
    window.coverSheetsList = $("#coverSheetsList");
    window.coverSheetsPanel = $("#coverSheetsPanel");
    window.reportGroupsList = $("#reportGroupsList");
    window.reportGroupPanel = $("#reportGroupsPanel");
    window.searchResults = $("#searchResults");
    setportfolioGroupFiltersdelegates();
}

function setportfolioGroupFiltersdelegates() {
    portfolioGroupFilters.delegate(".availableFilters", "change", function () {});
}

If you are using jQuery 1.7 or greater, the best solution is to use on() instead of delegate() . 如果您使用的是jQuery 1.7或更高版本,最好的解决方案是使用on()而不是delegate()

Your code using on() will be: 您使用on()代码将是:

portfolioGroupFilters.on("change", ".availableFilters", function () {});

Also, it's good to know that live() is deprecated: http://api.jquery.com/live/ 另外,很高兴知道不推荐使用live()http : //api.jquery.com/live/

As of jQuery 1.7, the .live() method is deprecated. 从jQuery 1.7开始,不推荐使用.live()方法。 Use .on() to attach event handlers. 使用.on()附加事件处理程序。 Users of older versions of jQuery should use .delegate() in preference to .live() . 较旧版本的jQuery的用户应优先使用.delegate()而不是.live()

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

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