|
Revision 53, 1.3 kB
(checked in by simon, 3 years ago)
|
|
fixed a bug in the remove test -- the tabindex wasn't being added back before testing removeAttribute("tabIndex")
|
| Line | |
|---|
| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" |
|---|
| 2 | "http://www.w3.org/TR/html4/strict.dtd"> |
|---|
| 3 | |
|---|
| 4 | <html> |
|---|
| 5 | |
|---|
| 6 | <head> |
|---|
| 7 | <title>Setting and removing the tabindex value of an element with JavaScript</title> |
|---|
| 8 | <script type="text/javascript"> |
|---|
| 9 | function log(message){ |
|---|
| 10 | text = document.createTextNode(message); |
|---|
| 11 | document.getElementById("log").appendChild(text); |
|---|
| 12 | document.getElementById("log").appendChild(document.createElement("br")); |
|---|
| 13 | } |
|---|
| 14 | function logSetAttribute(){ |
|---|
| 15 | var input = document.createElement("input"); |
|---|
| 16 | input.tabIndex = 1; |
|---|
| 17 | input.setAttribute("tabindex", 2); |
|---|
| 18 | log('setAttribute("tabindex")' + (input.tabIndex == 2 ? " yes" : " no")); |
|---|
| 19 | input.tabIndex = 1; |
|---|
| 20 | input.setAttribute("tabIndex", 2); |
|---|
| 21 | log('setAttribute("tabIndex")' + (input.tabIndex == 2 ? " yes" : " no")); |
|---|
| 22 | } |
|---|
| 23 | function hasTabindex(elem){ |
|---|
| 24 | var attr = elem.getAttributeNode("tabindex"); |
|---|
| 25 | return attr ? attr.specified : false; |
|---|
| 26 | } |
|---|
| 27 | function logRemoveAttribute(){ |
|---|
| 28 | var input = document.createElement("input"); |
|---|
| 29 | input.tabIndex = 1; |
|---|
| 30 | input.removeAttribute("tabindex"); |
|---|
| 31 | log('removeAttribute("tabindex")' + (hasTabindex(input) ? " no" : " yes")); |
|---|
| 32 | input.tabIndex = 1; |
|---|
| 33 | input.removeAttribute("tabIndex"); |
|---|
| 34 | log('removeAttribute("tabIndex")' + (hasTabindex(input) ? " no" : " yes")); |
|---|
| 35 | } |
|---|
| 36 | function run(){ |
|---|
| 37 | logSetAttribute(); |
|---|
| 38 | logRemoveAttribute(); |
|---|
| 39 | } |
|---|
| 40 | </script> |
|---|
| 41 | </head> |
|---|
| 42 | |
|---|
| 43 | <body onload="run()"> |
|---|
| 44 | <p id="log"></p> |
|---|
| 45 | </body> |
|---|
| 46 | |
|---|
| 47 | </html> |
|---|