[英]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.