简体   繁体   English

使一个div可见,另一个不可见

[英]Make one div visible and another invisible

I have two div tags, one is for the search and the other is for the results. 我有两个div标签,一个用于搜索,另一个用于搜索结果。 What I need is for when the submit button is clicked the results are returned and placed into the results div (with an iframe) and the search div should become hidden and the results div should be made visible. 我需要的是,当单击提交按钮时,返回结果并将其放入结果div(使用iframe),搜索div应该隐藏,结果div应该可见。

search div is initially set to visible (using the visibility to visible) and the results div is initially set to hidden (using the visibility to hidden). 搜索div最初设置为可见(使用可见性可见),结果div最初设置为隐藏(使用隐藏的可见性)。

Also, initially ther eis a huge white space at the bottom of the page where the hidden div is, so how do I make sure there is no extra white space at the bottom too. 此外,最初在隐藏div的页面底部有一个巨大的空白区域,所以我如何确保底部没有额外的空白区域。

You can use the display property of style. 您可以使用样式的display属性。 Intialy set the result section style as Intialy将结果部分样式设置为

style = "display:none"

Then the div will not be visible and there won't be any white space. 然后div将不可见,并且不会有任何空白区域。

Once the search results are being populated change the display property using the java script like 填充搜索结果后,使用java脚本更改display属性

document.getElementById("someObj").style.display = "block"

Using java script you can make the div invisible 使用java脚本可以使div不可见

document.getElementById("someObj").style.display = "none"

Making it invisible with visibility still makes it use up space. 通过可见性使其隐藏仍然会占用空间。 Rather try set the display to none to make it invisible, and then set the display to block to make it visible. 而是尝试将显示设置为none以使其不可见,然后将显示设置为阻止以使其可见。

I don't think that you really want an iframe, do you? 我不认为你真的想要一个iframe,对吗?

Unless you're doing something weird, you should be getting your results back as JSON or (in the worst case) XML, right? 除非你做了一些奇怪的事情,否则你应该把你的结果作为JSON或(在最坏的情况下)XML,对吧?

For your white box / extra space issue, try 对于您的白盒/额外空间问题,请尝试

style="display: none;"

instead of 代替

style="visibility: hidden;"

If u want to use display=block it will make the content reader jump, so instead of using display you can set the left attribute to a negative value which does not exist in your html page to be displayed but actually it do. 如果你想使用display = block它会使内容阅读器跳转,所以你可以将left属性设置为负值,而你的html页面中不存在这个值,但实际上却是这样。

I hope you must be understanding my point, if I am unable to make u understand u can message me back. 我希望你必须理解我的观点,如果我无法理解你,你可以给我回信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM