日期:2014-05-16 浏览次数:20332 次
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> <style> </style> </head> <body> <button id="add">添加</button> <script> function $(el){ return typeof el == 'string' ? document.getElementById(el) : el; } function $t(name, cot){ cot = cot || document; return cot.getElementsByTagName(name); } $('add').onclick = function(){ var p = document.createElement('p'); p.innerHTML = '<input name="test" /> <button>删除</button>'; $t('button', p)[0].onclick = function(){ this.parentNode.parentNode.removeChild( this.parentNode ); } document.body.appendChild(p); } </script> </body> </html>