日期:2014-05-16 浏览次数:20343 次
<script type="text/javascript"> var count = 0; function AddProduct() { if (count == 12) return; count += 1; var File1 = document.getElementById("file1"); var div = document.createElement("div"); var countTxt = document.createTextNode("SN" + count); var inputTxt = document.createElement("input"); inputTxt.type = "text"; inputTxt.name = "txtSN" + count; var btn = document.createElement("input"); btn.type = "button"; btn.value = "Cancel"; btn.onclick = function () { this.parentNode.parentNode.removeChild(this.parentNode); //alert(this.parentNode.nodeName); var str = File1.innerHTML; var re = /[^<]+/i; var n = File1.getElementsByTagName("div"); for (var k = 0; k < n.length; k++) { n[k].innerHTML = n[k].innerHTML.replace(re, "SN" + (k + 1)); n[k].getElementsByTagName("input").item(1).onclick = this.onclick; } count -= 1; } inputTxt.onchange = function () { } div.appendChild(countTxt); div.appendChild(inputTxt); div.appendChild(btn); File1.appendChild(div); } </script>
<!doctype html> <html> <head> <meta charset="utf-8"/> </head> <body> <input type="button" id="add" value="add" /> <div id="file1"></div> <script type="text/javascript"> document.getElementById('add').onclick = function(){ var File1 = document.getElementById("file1"); AddProduct(File1); if(!initEvent.hsdInit){ initEvent(File1); } } var count = 0; function AddProduct(container) { if (count == 12) return; count +=