标签:onclick inpu lan setattr doc tle dom charset get
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <div id="i1"> <input type="button" value="+" onclick="add_1();" style="background-color: red"> <input type="button" value="+" onclick="add_2()" style="background-color: yellow"> </div> <script> function add_1(){ var tag = "<p><input type=‘text‘ style=‘background-color:red‘ /></p>" ; document.getElementById(‘i1‘).insertAdjacentHTML(‘beforeEnd‘,tag); } function add_2(){ var tag = document.createElement(‘input‘); tag.setAttribute(‘type‘,‘text‘) tag.style.backgroundColor =‘yellow‘; var p1 = document.createElement(‘p‘); p1.appendChild(tag) document.getElementById(‘i1‘).appendChild(p1) } </script> </body> </html>
标签:onclick inpu lan setattr doc tle dom charset get
原文地址:http://www.cnblogs.com/Charles9703/p/7436526.html