简体   繁体   English

此JavaScript / jQuery代码是否会在ie8或其他浏览器中泄漏?

[英]Does this JavaScript / jQuery code leak in ie8 or other browsers?

I spent a lot of time reading about memory leaks. 我花了很多时间阅读有关内存泄漏的信息。 I'm confused because what was true for ie6 is not true anymore for ie8 or newer browsers. 我很困惑,因为ie6的真实性不再适用于ie8或更高版本的浏览器。 From what I understand, this code could/would leak because, in a function, I created a DOM element on which I bind an event. 据我了解,该代码可能/会泄漏,因为在函数中,我创建了一个绑定事件的DOM元素。 Is my understanding correct? 我的理解正确吗? If so, would the code in comments would leak, too? 如果是这样,注释中的代码也会泄漏吗? If it does, what would be the best approach to not have a leak? 如果是这样,没有泄漏的最佳方法是什么?

function somefunc() {
    var $CodeInstallation, $selInstallation;

    $CodeInstallation = jQuery(<...some form tag...>);

    $selInstallation = jQuery(
        '<input value="select"' +
        ' type="button" name="selInstallation" ' +
        ' id="idSelInstallation"/>')
        .appendTo($CodeInstallation.parent());

    // should I do that instead  ???
    /*
    jQuery('<input value="select"' +
       ' type="button" name="selInstallation" ' +
       ' id="idSelInstallation"/>')
       .appendTo($CodeInstallation.parent());
    $selInstallation = jQuery('#idSelInstallation');
    */

    $selInstallation.click( function() {
        alert('click!');
    }); // click
}

感谢Pointy和KevinB。答案是否定的,原因是jQuery处理事件而不是附加到DOM对象的方式。

暂无
暂无

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

相关问题 我的Javascript代码在IE中不起作用,但在其他浏览器中也可以正常工作 - My Javascript code does not work in IE but works fine in other browsers jquery:IE8中的“异常抛出但未被捕获”,但在其他浏览器中有效 - jquery: “Exception thrown and not caught” in IE8, but works in other browsers Javascript在IE8中工作但不是chrome和safari以及其他最新的浏览器 - Javascript working in IE8 but not chrome and safari and other latest browsers dojo查询不适用于IE7,但可以在IE8和其他浏览器上使用吗? - dojo query does not work on IE7 but does on IE8 and other browsers? jQuery,JavaScript和IE8 - jQuery, javascript, and IE8 IE8不能与jQuery .show()一起使用,并且不能在所有其他浏览器(包括ie9)上使用 - IE8 not working with jQuery .show() and working on all other browsers including ie9 Javascript代码不适用于IE11,但适用于所有其他浏览器 - Javascript code does not work on IE11, but works on all other browsers IE8中img掩盖的jquery鼠标事件-所有其他平台/浏览器工作正常 - jquery mouse events masked by img in IE8 - all other platforms/browsers work fine 使用javascript在IE8和其他浏览器上获取body类的标准解决方案是什么? - What is the standard solution to get body class at IE8 and other browsers with javascript 为什么&#39;string&#39;[0]在ie8 + IIS7.5上的行为与其他浏览器或本地文件不同? - Why does 'string'[0] behave differently on ie8 + IIS7.5 than other browsers or local file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM