我有一些javascript代码,它用mouseover回调创建一个img标记,并将img标记添加到页面中。问题是每次调用回调时(在Firefox控制台中)都会发生一个javascript语法错误。
此代码演示了问题…
var imgUrl = 'http://sstatic.net/so/img/logo.png';
var img = document.createElement('img');
img.setAttribute('src', imgUrl);
img.setAttribute('onmouseover', function() {
alert('mouseover ' + imgUrl);
});
document.body.appendChild(img);
即使回调函数是空函数,也会发生语法错误。
有人能解释是什么导致了语法错误以及如何修复它吗?
(我在Win XP上使用的是FF 3.5.2。)