2016-07-26 48 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") {