1

需要知道如何将变量应用于 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>
4

1 回答 1

3

You're trying to write

elem[i][actionIn] = ...;
于 2013-04-23T14:23:23.477 回答