-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";}

    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

2 に答える 2

1

.2 つの角かっこのペアの間に は必要ありません。

elem[i][actionIn]elem[i][actionOut]

十分なはずです。

于 2013-04-23T14:52:46.860 に答える