我花了很多时间阅读有关内存泄漏的信息。我很困惑,因为ie6的真实性不再适用于ie8或更高版本的浏览器。据我了解,此代码可能/会泄漏,因为在函数中,我创建了一个绑定事件的DOM元素。我的理解正确吗?如果是这样,注释中的代码也会泄漏吗?如果是这样,没有泄漏的最佳方法是什么?
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对象的方式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句