相关联的匿名函数下面的代码不起作用调用与事件
<input id="inp" type="text"
onfocus="(function(){document.getElementById('inp').style.background="yellow";})">
但这个代码工作,因为我希望它的工作
<input id="inp" type="text"
onfocus="(function(e){document.getElementById('inp').style.background ='yellow';}(this)">
为什么没有第一个代码工作?
内联事件处理程序由于这个原因是不好的做法。引号在HTML属性和字符串文字之间变得模糊不清。 – 4castle
提示:看看“黄色”附近的语法高亮区别的差异 – 4castle