我想检查表的特定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"但我仍然得到同样的错误。
我做错了什么?
答案 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";
}