如果显示为无

时间:2016-07-26 05:47:11

标签: javascript

我想检查表的特定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";
  }

我试过了,但我在if行收到错误ncaught SyntaxError: Unexpected identifier

我尝试将此行设置为变量,然后检查这是否为变量是== to" none"但我仍然得到同样的错误。

我做错了什么?

2 个答案:

答案 0 :(得分:3)

变化:

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

要:

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

答案 1 :(得分:3)

如果陈述需要围绕条件的括号。

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";
}