| 1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
|---|
| 2 | "http://www.w3.org/TR/html4/loose.dtd"> |
|---|
| 3 | |
|---|
| 4 | <html> |
|---|
| 5 | |
|---|
| 6 | <head> |
|---|
| 7 | <title>Getting attribute values and defaults</title> |
|---|
| 8 | <script type="text/javascript"> |
|---|
| 9 | function getPropName(attrName){ |
|---|
| 10 | switch(attrName){ |
|---|
| 11 | case "colspan": |
|---|
| 12 | return "colSpan"; |
|---|
| 13 | case "rowspan": |
|---|
| 14 | return "rowSpan"; |
|---|
| 15 | case "valuetype": |
|---|
| 16 | return "valueType"; |
|---|
| 17 | default: |
|---|
| 18 | return attrName; |
|---|
| 19 | } |
|---|
| 20 | } |
|---|
| 21 | function log(attrName, elemName){ |
|---|
| 22 | var log = document.getElementById("log"); |
|---|
| 23 | var elem = document.getElementsByTagName(elemName)[0]; |
|---|
| 24 | log.appendChild(document.createTextNode(elemName |
|---|
| 25 | + '.getAttribute("' + attrName + '") = ')); |
|---|
| 26 | var getAttrValue = elem.getAttribute(attrName); |
|---|
| 27 | getAttrValue = getAttrValue == null ? "null" : '"' + getAttrValue + '"'; |
|---|
| 28 | log.appendChild(document.createTextNode(getAttrValue)); |
|---|
| 29 | log.appendChild(document.createElement("br")); |
|---|
| 30 | var propName = getPropName(attrName); |
|---|
| 31 | log.appendChild(document.createTextNode(elemName |
|---|
| 32 | + '["' + propName + '"] = ')); |
|---|
| 33 | var propValue = elem[propName]; |
|---|
| 34 | propValue = propValue == null ? "null" : '"' + propValue + '"'; |
|---|
| 35 | log.appendChild(document.createTextNode(propValue)); |
|---|
| 36 | log.appendChild(document.createElement("br")); |
|---|
| 37 | } |
|---|
| 38 | function run(){ |
|---|
| 39 | var userAgentTextNode = document.createTextNode(navigator.userAgent); |
|---|
| 40 | document.getElementById("user-agent").appendChild(userAgentTextNode); |
|---|
| 41 | log("colspan", "td"); |
|---|
| 42 | log("enctype", "form"); |
|---|
| 43 | log("frameborder", "iframe"); |
|---|
| 44 | log("method", "form"); |
|---|
| 45 | log("rowspan", "td"); |
|---|
| 46 | log("scrolling", "iframe"); |
|---|
| 47 | log("shape", "a"); |
|---|
| 48 | log("span", "colgroup"); |
|---|
| 49 | log("type", "input"); |
|---|
| 50 | log("type", "button"); |
|---|
| 51 | log("valuetype", "param"); |
|---|
| 52 | } |
|---|
| 53 | </script> |
|---|
| 54 | </head> |
|---|
| 55 | |
|---|
| 56 | <body onload="run()"> |
|---|
| 57 | <p><a href="http://www.w3.org/TR/html401/index/attributes.html">HTML4 |
|---|
| 58 | defines defaults for a number of attributes.</a> |
|---|
| 59 | Some browsers return the default value when an attribute value is |
|---|
| 60 | requested on an element that does not have a value specified for |
|---|
| 61 | that attribute, and some do not. |
|---|
| 62 | This page shows the results of requesting a value for each of the |
|---|
| 63 | attributes with defaults in HTML4, other than 2 that are |
|---|
| 64 | marked as deprecated ("clear", and "version"), on elements |
|---|
| 65 | with no value set for those attributes.</p> |
|---|
| 66 | <h2>User agent</h2> |
|---|
| 67 | <p id="user-agent"> |
|---|
| 68 | <h2>Results</h2> |
|---|
| 69 | <p id="log"></p> |
|---|
| 70 | <hr> |
|---|
| 71 | <table> |
|---|
| 72 | <colgroup></colgroup> |
|---|
| 73 | <tr><td></tr> |
|---|
| 74 | </table> |
|---|
| 75 | <form action="#"> |
|---|
| 76 | <div> |
|---|
| 77 | <input> |
|---|
| 78 | <button></button> |
|---|
| 79 | </div> |
|---|
| 80 | </form> |
|---|
| 81 | <iframe></iframe> |
|---|
| 82 | <p><a href="#">a</a></p> |
|---|
| 83 | <object><param name="param1"></object> |
|---|
| 84 | </body> |
|---|