English 中文(简体)
我如何利用 Java(而不是 j)来展示:诺言?
原标题:How do I use JavaScript (not jQuery) to make something display:none?
  • 时间:2010-04-06 21:43:15
  •  标签:
  • javascript

附录一包含一个叫做#container-main"的内容。 我如何使<代码>显示:无 NOT 使用 j子

最佳回答
document.getElementById( container-main ).style.display =  none ;
问题回答

假定您指的是<代码>id 集装箱的特性为container-main。 然后,在 Java文中,你做的是

document.getElementById( container-main ).style.display =  none ;

虽然其他答案是正确的,但为了防止可能出现的错误,我建议首先提及你的OM要素,然后确保这一要素的存在和拥有财产,而不是把一切放在一线上。 如果由于某种原因,该页上不再存在集装箱主干的成分,那么所建议的一班机将产生一个联合材料错误。

var myNode = document.getElementById( container-main ); // Attempt to get the reference first
if ( myNode && myNode.style ) { // make sure you did get an element, and if so...
    myNode.style.display =  none ; // then operate on it s properties.
}

此外,许多人有错误的概念,即每一次遗产改建都需要另一人要求获得ById. ......情况并非如此,需要增加人力部的模拟(可能变得缓慢)。

document.getElementById( container-main ).style.display =  none ;
document.getElementById( container-main ).style.color =  black ; // getting by id a second time can be slow

-

var myNode = document.getElementById( container-main );
if ( myNode && myNode.style ) {
    myNode.style.display =  none ;
    myNode.style.color =  black ; // but using a reference a second time costs nothing.
}
document.getElementById( container-main ).style.display =  none ;

<代码>>>0 隐瞒了该元素,因此它不占用任何空间,而<代码> 显示=隐蔽的仍然占用空间,但不能认为。

也可以使用

document.getElementById( container-main ).style.visibility = "hidden";

edited: document.getElementById( container-main ).style.display = none ;





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签