日期:2014-05-17  浏览次数:20950 次

JS创建HTML标签
<script type="text/javascript">
var count = 0;
function Add(){
   count += 1;
   var File1 = document.getElementById("file1");
   var div = document.createElement("div");
   var btnJiaHao = document.createElement("input");
   btnJiaHao.type = "button";
   btnJiaHao.value = "+";
   btnJiaHao.id = count;
   btnJiaHao.onclick = function(){
   		jiahao(this);	
   }
   var inputTxt = document.createElement("input");
   inputTxt.type = "text";
   inputTxt.name = "txt"+count;
   inputTxt.id = "txt_"+count;
   inputTxt.value = "0";
   var btn = document.createElement("input");
   btn.type = "button";
   btn.value = "-";
   btn.id = count;
   btn.onclick = function(){
       jianhao(this);
   }
  
   div.appendChild(btnJiaHao);
   div.appendChild(inputTxt);
   div.appendChild(btn);
   File1.appendChild(div);
}
function jianhao(t){
	var txt_id = "txt_" + t.id;
	var v = document.getElementById(txt_id).value;
	v = v - 1;
	document.getElementById(txt_id).value = v;
}
function jiahao(t){
	var txt_id = "txt_" + t.id;
	var v = document.getElementById(txt_id).value;
	v = parseInt(v) + 1;
	document.getElementById(txt_id).value = v;
}
</script>

<input type="button" name="button" value="增加" onclick="Add();" />
<div id="file1"></div>

?