Javascript controls html element display/hide implementation code
Source: Internet
Author: User
1. Compile js Functions <Script type = "text/javascript">
Function display (y) {$ (y). style. display = ($ (y). style. display = "none ")? "": "None ";}
Function $ (s) {return document. getElementById (s );}
</Script>
2. Add the id attribute to the html element to be displayed/hidden <Table>
<Tr id = "menu">
<Td> control the display/hide of this tr </td>
</Tr>
</Table>
3. Add buttons and links to trigger js functions. <Input type = "button" onclick = "display ('menu ')" value = "show/hide"/>
<A href = "#" onclick = "display ('menu ')"> display/hide </a>
Javascript hide layer <div id = "layer" style = "display: none;"> advertisement </div>
<Input type = "botton" onclick = "display (layer)">
2. Two methods to hide and display page controls using javascript Javascript controls the hidden display of page controls. The difference between the two methods is whether the controls are still occupied on the page after they are hidden.
Method 1: Document. all ["PanelSMS"]. style. visibility = "hidden ";
Document. all ["PanelSMS"]. style. visibility = "visible ";
Method 2: Document. all ["PanelSMS"]. style. display = "none ";
Document. all ["PanelSMS"]. style. display = "inline ";
Method 1 after hiding, the page location is still occupied by the control but not displayed.
Method 2 Hide and the page location is not occupied
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service