Created
June 1, 2012 06:40
-
-
Save cherenkov/2849594 to your computer and use it in GitHub Desktop.
javascript DOM で、ノード属性値変更についてですが。 以下のよ.. - 人力検索はてな http://q.hatena.ne.jp/1338473476
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> | |
| <meta charset="utf-8"> | |
| </head> | |
| <body> | |
| <table> | |
| <thead> | |
| <tr> | |
| <td>タイトル</td> | |
| <td>行追加</td> | |
| </tr> | |
| </thead> | |
| <tbody id="p2146-tbody"> | |
| <tr> | |
| <input name="ids[]" type="hidden" value="123" /> | |
| <td> | |
| <input name="chapts[]" type="text" value="DBから取得したデータ①" /> | |
| </td> | |
| <td> | |
| <input onclick="addList(this)" type="button" value="+" /> | |
| </td> | |
| </tr> | |
| <tr> | |
| <input name="ids[]" type="hidden" value="124" /> | |
| <td> | |
| <input name="chapts[]" type="text" value="DBから取得したデータ②" /> | |
| </td> | |
| <td> | |
| <input onclick="addList(this)" type="button" value="+" /> | |
| </td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| </body> | |
| <script> | |
| function addList(btn){ | |
| var tr = btn.parentNode.parentNode.cloneNode(true); | |
| var inputs = tr.getElementsByTagName('input'); | |
| for (var i = 0; i < inputs.length; i++) { | |
| if (inputs[i].name == 'ids[]') { | |
| inputs[i].value = ''; | |
| } | |
| } | |
| btn.parentNode.parentNode.parentNode.insertBefore(tr, btn.parentNode.parentNode.nextSibling); | |
| } | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment