2016-07-26 64 views
-1

我想檢查表格的特定tr(行)是否具有無顯示值。如果是的話那麼我想它來執行一些不同的代碼對我來說:檢查(如果語句)表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

我試着將此行設置爲一個變量,然後檢查是否變量是==爲「無」,但我仍然收到相同的錯誤。

我在做什麼錯?

+1

它應該是'if(CONDITION)'而不是'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") {