声明多个var';具有多个if';s、 但是做任何一个if';s、 不是一个,不是全部,也不是没有。[HTML+;JavaScript]

声明多个var';具有多个if';s、 但是做任何一个if';s、 不是一个,不是全部,也不是没有。[HTML+;JavaScript],javascript,html,Javascript,Html,大概是这样的: <!-- HTML on page --> <!-- hide the following div by class--> <div id="bed" class="blankets"> We sell blankets </div> <!-- hide the following div by ID --> <div id="animal" class="frogs"> We sell

大概是这样的:

<!-- HTML on page -->

<!-- hide the following div by class-->
<div id="bed" class="blankets"> 
    We sell blankets
</div>

<!-- hide the following div by ID -->
<div id="animal" class="frogs">
    We sell frogs
</div>

<!-- this is the only div I want visible -->
<div id="house" class="speakers">
    We sell houses and speakers
</div>

<!-- hide the following div by class -->
<div id="car" class="suvs">
    We sell cars
</div>

我只想看到页面中间的内容,而如果顶部改变了服务器端的值,但底部保持不变,底部仍然隐藏,现在我必须更新代码到值。 我在互联网上看到的只是执行一个变量的方法,如果所有变量都匹配,或者(另一个)匹配。它必须将整个规则与单个点相匹配

我想这是工作的浏览器中提到的评论请。 我也不知道如何使用评论。我使用了//和/*/,是/*\结束评论的方法吗

更新


现在,如何为类上的var添加另一行,以便隐藏第四个div?

很难确定您想要在这里实现什么,但我可以解释您当前的脚本的功能:

// The variable 'div' refers to <div id="frogs">
var div = document.getElementById("frogs"); 

// If 'div' exists, remove it
if (div) {
    div.parentNode.removeChild(div);
};

// The variable 'cur_columns' refers to all elements with class="speaker"
var cur_columns = document.getElementsByClassName('speakers');
// ...and now it refers to all elements with class="suvs"!
var cur_columns = document.getElementsByClassName('suvs');

// If 'div' exists, remove it (again)
if (div) {
    div.parentNode.removeChild(div);
};
//变量'div'指的是
var div=document.getElementById(“青蛙”);
//如果“div”存在,请将其删除
如有需要(分区){
div.parentNode.removeChild(div);
};
//变量“cur_columns”引用class=“speaker”的所有元素
var cur_columns=document.getElementsByClassName('speakers');
//…现在它使用class=“SUV”引用所有元素!
var cur_columns=document.getElementsByClassName('suvs');
//如果“div”存在,请将其删除(再次)
如有需要(分区){
div.parentNode.removeChild(div);
};

你能在描述中更具体吗?尼古拉斯,这一部分并不完全清楚:“我只想看到页面中间的内容,而如果顶部改变了服务器端的值,但底部保持不变,底部仍然隐藏,现在我必须更新代码到值。”-你能详细说明吗?试着写一个条件和结果的列表(用伪代码),解释各种可能性以及在每种情况下你希望发生什么。更新了我的代码。我不知道如何更好地描述这篇文章的标题/描述。你更新的代码毫无意义。我可以解释为什么没有意义,但真正的问题是我们不知道你想要什么。你能详细说明一下你希望发生什么吗?我希望第二个变量删除指定了类的两个div,不管它们是有效的还是无效的。我想通过它的ID隐藏第一个div,在我的网站上,我希望能够按它们的类指定多个div,并执行相同的操作(删除两个div),但是,如果某个类被更新,那么即使其中一个类已不在网页上,代码仍将执行。我还希望能够使用div的ID完成这项工作。使用有效值更新javascript。我在代码中解释了更多内容。你还需要我怎么解释呢,?
// The variable 'div' refers to <div id="frogs">
var div = document.getElementById("frogs"); 

// If 'div' exists, remove it
if (div) {
    div.parentNode.removeChild(div);
};

// The variable 'cur_columns' refers to all elements with class="speaker"
var cur_columns = document.getElementsByClassName('speakers');
// ...and now it refers to all elements with class="suvs"!
var cur_columns = document.getElementsByClassName('suvs');

// If 'div' exists, remove it (again)
if (div) {
    div.parentNode.removeChild(div);
};