0

これは単純なはずです....ここで何が間違っているのかわかりません。私のHTMLには、

<a onmouseover="test(this.id)" id="ok">test me</a>

私のヘッダーには、このスクリプトがあります。

<script>
    function test(this.id){
        alert(id);
    }
</script>
4

3 に答える 3

3

関数のパラメータ名は、式ではなく、有効な識別子でなければなりません:

FormalParameterList :
    識別子
    FormalParameterList識別子

this.idは式であり、プロパティ アクセサーthis.idであるため、正式なパラメーター名として使用すると構文エラーになります。変化する

function test(this.id){
    alert(id);
}

function test(id){
    alert(id);
}

// or
function test(foo){
    alert(foo);
}

または単に

<a onmouseover="alert(this.id)" id="ok">test me</a>
于 2013-03-11T21:09:09.480 に答える
2

これ:

<script>
    function test(id){
        alert(id);
    }
</script>
于 2013-03-11T21:08:57.900 に答える
1

これを試して:

<a onmouseover="test(this.id)" id="ok">test me</a>

<script>
    function test(id){
        alert(id);
    }
</script>

デモ

于 2013-03-11T21:09:59.590 に答える