Home >Web Front-end >JS Tutorial >Two ways to hide and show controls in js_javascript skills
There are two ways to hide controls using JavaScript, one is by setting the "display" and "visibility" attributes of the control's style.
The control is visible when style.display="block" or style.visibility="visible", and is invisible when style.display="none" or style.visibility="hidden". The difference is that "display" not only hides the control, but also the hidden control no longer occupies the position occupied when displayed, while the control hidden by "visibility" only sets the control to be invisible, and the control still occupies its original position.
function displayHideUI() { var ui =document.getElementById("bbs"); ui.style.display="none"; } function displayShowUI() { var ui =document.getElementById("bbs"); ui.style.display="";//display为空的话会好使,为block会使后边的空间换行 } function visibilityHideUI() { var ui =document.getElementById("bbs"); ui.style.visibility="hidden"; } function visibilityShowUI() { var ui =document.getElementById("bbs"); ui.style.visibility="visible"; } </script>
Value Description
none This element will not be displayed.
block This element will be displayed as a block-level element with line breaks before and after this element.
inline default. This element will be displayed as an inline element with no line breaks before or after the element.
inline-block Inline block element. (New value in CSS2.1)
list-item This element will be displayed as a list.
run-in This element will appear as a block-level element or an inline element, depending on the context.
compact There is a value compact in CSS, but it has been removed from CSS2.1 due to lack of widespread support.
marker There is a value marker in CSS, but it has been removed from CSS2.1 due to lack of widespread support.
table This element will be displayed as a block-level table (similar to f5d188ed2c074f8b944552db028f98a1) with line breaks before and after the table.
inline-table This element will be displayed as an inline table (similar to f5d188ed2c074f8b944552db028f98a1) without line breaks before and after the table.
table-row-group This element will be displayed as a group of one or more rows (similar to 92cee25da80fac49f6fb6eec5fd2c22a).
table-header-group This element will be displayed as a group of one or more rows (similar to ae20bdd317918ca68efdc799512a9b39).
table-footer-group This element will be displayed as a group of one or more rows (similar to 06669983c3badb677f993a8c29d18845).
table-row This element will be displayed as a table row (similar to a34de1251f0d9fe1e645927f19a896e8).
table-column-group This element will be displayed as a group of one or more columns (similar to 879b49175114808d868f5fe5e24c4e0b).
table-column This element will be displayed as a cell column (similar to 581cdb59a307ca5d1e365becba940e05)
table-cell This element will be displayed as a table cell (similar to b6c5a531a458a2e790c1fd6421739d1c and b4d429308760b6c2d20d6300079ed38e)
table-caption This element will be displayed as a table title (similar to 63bd76834ec05ac1f4c0ebbeaafb0994)
inherit specifies that the value of the display attribute should be inherited from the parent element.
The problem solved today is to give the label.error class defined by css an id in the jsp page, and then control the visibility of the id to clear the js prompt information when the div is collapsed. The details are as follows:
In the function of preparing the interface var label1 = document.getElementById("label1");
$(document).ready(function() { $(".flipp .span4").click(function() { $(this).parent().next().toggle(); $(this).parent().parent().prevAll().find(".panel").hide(); $(this).parent().parent().nextAll().find(".panel").hide(); var label1 = document.getElementById("label1"); label1.style.display="none"; })
Then add in the corresponding place in jsp:
<label class="error" id="label1" for="currentPWD" generated="true" style="display:inline"></label>
For the label.error class defined by CSS, you can use $("label.error").removeAttr("style").attr("style", "display: none;"); to achieve the above function. Moreover, it seems that there is no need to define the id value for the label at the corresponding location underground.