2016-07-26 15 views
-1

テーブルの特定のtr(行)に表示値がないかどうかをチェックしたいと思います。それは、私はそれが私のために、いくつかの異なるコードを実行したいならば:表示(if文)テーブルtr要素が表示されない場合

if $('.table')[0].rows[5].style.display == "none" { 
    $('.table')[0].rows[5].style.display = "none"; 
    $('.table')[0].rows[4].style.display = "none"; 
    }else{ 
    $('.table')[0].rows[5].style.display = "table-row"; 
    $('.table')[0].rows[4].style.display = "table-row"; 
    } 

を私はこれを試してみましたが、私はもし行でエラーncaught SyntaxError: Unexpected identifierを取得しています。

私はこの行を変数に設定して、これが可変であるかどうかをチェックしてみました==は "none"ですが、私はまだ同じエラーを受けていました。

私は間違っていますか?

+1

これは 'if CONDITION'ではなく' if(CONDITION) 'であると考えられます。 – choz

+1

これは有効なjavascript構文ではありません。 [ステートメントにかっこが必要な場合](http://www.w3schools.com/js/js_if_else.asp)。 –

答えて

2

文は、条件を括弧で囲む必要がある場合。

if ($('.table')[0].rows[5].style.display == "none") { 
    $('.table')[0].rows[5].style.display = "none"; 
    $('.table')[0].rows[4].style.display = "none"; 
} 
else { 
    $('.table')[0].rows[5].style.display = "table-row"; 
    $('.table')[0].rows[4].style.display = "table-row"; 
} 
3

変更:

if $('.table')[0].rows[5].style.display == "none" { 

へ:

if ($('.table')[0].rows[5].style.display === "none") { 
関連する問題