我正在尝试动态更新使用 Prototip 和 Prototype 制作的工具提示。我尝试这样做的方式可能不是最好的方式(所以如果你知道更好的方式会有所帮助),但我能想到的唯一方法是将javascript保存在 div 元素中并更新div 元素内的 javascript 以更新工具提示。但是,这似乎是内存泄漏,因为每次更新 javascript 时,都会创建一个新的 Tip 对象并将其存储在内存中。如果没有更好的方法,我该如何清除内存?
我制作了这个简单的脚本来测试内存泄漏,现在我需要弄清楚如何制作它,以便在这个示例中修补内存泄漏。
for (i=0; i<1000; i++) {
$('testdiv').update("<script type='text/javascript'> new Tip('chips_tip', 'Your Chips', {style: 'creamy',stem: 'topLeft',hook: { mouse: true, tip: 'topLeft' },offset: { x: 10, y: 16 },delay: 0.04,width: 85}); <\/script>");
}
以下是工具提示的 javascript 通常是什么:
new Tip('element', "Description", {
style: 'creamy',
stem: 'topLeft',
hook: { mouse: true, tip: 'topLeft' },
offset: { x: 10, y: 16 },
delay: 0.04,
width: 85
});