jQuery.fn.testeee = function(_msg)
{
alert(_msg);
$(this[0]).overlay({
onBeforeLoad: function()
{
alert(_msg);
}
}).load();
};
$("#popup").testeee ('test');
$("#popup").testeee ('another_test');
这显示:
- 测试
- 测试
- 另一个测试
- 测试
分配给 onBeforeLoad 的匿名函数中的 alert() 一直显示“测试”。我试试这个:
jQuery.fn.testeee = function(_msg)
{
alert(_msg);
$(this[0]).overlay({
onBeforeLoad: static_func(_msg)
}).load();
};
function static_func(_msg)
{
alert(_msg);
}
$("#popup").testeee ('test');
$("#popup").testeee ('another_test');
它工作得很好。它显示:
- 测试
- 测试
- 测试
- 测试
任何人都知道为什么会发生这种情况?