我需要修复这个 javascript 错误,我有“变量上的 . 运算符后缺少名称”。这是我正在尝试使用的当前代码。
<!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>