/ Published in: JavaScript
Expand |
Embed | Plain Text
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Toggle Display in Javascript</title> <style type="text/css"> /* normalerweise in eigener .css-Datei */ #container { border: 1px outset #BBBBBB; padding: 2px; width: 15em; } #loginBox { display: none; border: 1px inset #BBBBBB; padding: 2px; } .c { text-align: center; } </style> <script type="text/javascript" language="javascript"> /* normalerweise in eigener .js-Datei */ function getStyle(oElm, strCssRule) { var strValue = ""; if(document.defaultView && document.defaultView.getComputedStyle){ strValue = document.defaultView.getComputedStyle(oElm,"").getPropertyValue(strCssRule); } else if(oElm.currentStyle) { strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){ return p1.toUpperCase(); }); strValue = oElm.currentStyle[strCssRule]; } return strValue; } function toggleDisplay(element) { if (getStyle(element,'display') == "none") { element.style.display = "block"; } else { element.style.display = "none"; } } </script> </head> <body> <form id="login" method="post" action="#"> <div id="container"> <p class="c"><a href="#" onclick="toggleDisplay(document.getElementById('loginBox')); return false;">Login</a></p> <div id="loginBox"> <table> <tr><td><label for="nameField">Name:</label></td><td><input id="nameField" type="text" name="name" /></td></tr> <tr><td><label for="passField">Passwort:</label></td><td><input id="passField" type="password" name="password" /></td></tr> </table> <p class="c"><input type="submit" value="Login" /></p> </div> </div> </form> </body> </html>
You need to login to post a comment.
