2011-07-28 8 views
1

私はCSSで2つの別のクラスを持っていますが、クリックするとリンクを切り替える必要があります。私は警告を取得してもいけないので、私はonClick一部に問題があると思う:事前onClickは 'a'要素では動作しません

答えて

4
if (document.getElementById(word).className == "remaining";) { 
------------------------- E R R O R ----------------------^ 

<script type="text/javascript"> 
    function find(word) { 
     alert('check'); 
     if (document.getElementById(word).className == "remaining";) { 
     document.getElementById(word).className = "found"; 
     } else { 
     document.getElementById(word).className = "remaining"; 
     }; 
    }; 
    </script> 
[...] 
<a href="#" id="word20" class="remaining" onClick="find('word20');">LOL</a> 

おかげでここにスプリアスセミコロンがエラーです。

Firefox JavaScriptのエラーコンソールでエラーが見つかりました。 Ctrl + Shift + Jを使用して起動するのは簡単です。

+0

ありがとうございました:D –

2

あなたはsintaxエラーを持って、スクリプトは次のようにする必要があります:

<script type="text/javascript"> 
function find(word) { 
    alert('check'); 
    if (document.getElementById(word).className == "remaining") { 
    document.getElementById(word).className = "found"; 
    } else { 
    document.getElementById(word).className = "remaining"; 
    }; 
}; 

削除します。 「残り」の隣に

関連する問題