これは単純なはずです....ここで何が間違っているのかわかりません。私のHTMLには、
<a onmouseover="test(this.id)" id="ok">test me</a>
私のヘッダーには、このスクリプトがあります。
<script>
function test(this.id){
alert(id);
}
</script>
これは単純なはずです....ここで何が間違っているのかわかりません。私のHTMLには、
<a onmouseover="test(this.id)" id="ok">test me</a>
私のヘッダーには、このスクリプトがあります。
<script>
function test(this.id){
alert(id);
}
</script>
関数のパラメータ名は、式ではなく、有効な識別子でなければなりません:
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>
これ:
<script>
function test(id){
alert(id);
}
</script>
これを試して:
<a onmouseover="test(this.id)" id="ok">test me</a>
<script>
function test(id){
alert(id);
}
</script>