Created
December 14, 2010 15:08
-
-
Save wsdookadr/740548 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>Value vs. Reference</title> | |
| </head> | |
| <body> | |
| <table> | |
| <tbody> | |
| <tr> | |
| <td><input type="button" value="to_input" class="lupa" /></td> | |
| <td><span atr="a">1</span></td> | |
| <td><span atr="b">2</span></td> | |
| <td><span atr="c">3</span></td> | |
| </tr> | |
| <tr> | |
| <td><input type="button" value="to_input" class="lupa" /></td> | |
| <td><span atr="d">4</span></td> | |
| <td><span atr="e">5</span></td> | |
| <td><span atr="f">6</span></td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <br /> | |
| <script type="text/javascript"> | |
| function to_input(obj, index) { | |
| console.log("inside i="+index+"\n"); | |
| var i = index; | |
| var dims = obj.parentNode.parentNode.getElementsByTagName('td');//iterate over spans in that tr | |
| var tmpVal, atr; | |
| for(var j = 1; j < dims.length; j++) {//skip, first which is the td with button in it | |
| atr = dims[j].getElementsByTagName('span')[0].getAttribute('atr'); | |
| tmpVal = dims[j].getElementsByTagName('span')[0].innerHTML; | |
| console.log(atr+" "+i+" "+j+"\n"); | |
| dims[j].innerHTML = '<input type="text" name="' + atr + i+ j + '" value="' + tmpVal + '" />'; | |
| } | |
| } | |
| var anc = document.getElementsByClassName('lupa'); | |
| for (var i = 0; i < anc.length; i++) {// anc are the tds with button in them | |
| console.log("before i="+i+"\n"); | |
| anc[i].onclick = (function(i) { | |
| return function() { | |
| to_input(this, i); | |
| }; | |
| })(i); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment