変数を 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";}
document.write(actionIn+" "+actionOut);
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>