Javascript错误后丢失名称。运算符可变函数 [英] Javascript error missing name after . operator on variable function
本文介绍了Javascript错误后丢失名称。运算符可变函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要修复这个javascript错误,我有缺少名称后的操作符变量。这是我目前正在努力工作的代码。
I need to fix this javascript error I am having "missing name after . operator on variable". This is my current code I am trying to get working.
<!DOCTYPE html>
<html>
<body onload="myFunction()">
<select>
<option>1</option>
</select>
<br/>
<select>
<option>1</option>
</select>
<script>
function myFunction()
{
if(typeof document.body.ontouchstart == "undefined"){actionIn = "onmouseover"; actionOut = "onmouseout"}
else{actionIn = "ontouchstart"; actionOut = "ontouchend";}
var elem = document.getElementsByTagName("SELECT");
for (var i = 0;i < elem.length; i++){
elem[i].[actionIn] = function(){this.style.background='red';}
elem[i].[actionOut] = function(){this.style.background='';}
}
}
</script>
</body>
</html>
推荐答案
Use either dot or bracket notation, not both:
elem[i][actionIn] = function(){this.style.background='red';}
elem[i][actionOut] = function(){this.style.background='';}
这篇关于Javascript错误后丢失名称。运算符可变函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文