您当前的位置:天天ASP学习网页制作JavaScript → 文章内容

动态添加删除input元素(含动态创建数组)

作者:本站  来源:本站整理  发布时间:2016-05-05 21:24:54
<script type="text/javascript"> 
function deleteE(cid,id){ 

var father = document.getElementById("buynote_"+cid); 
var child = document.getElementById(cid+"_"+id); 
father.removeChild(child); 
} 



//创建元素
function addE(cid){ 
//数组元素
   <%
dim sqlb,rsb,cid,m
 
sqlb= "select * from food_class"
set rsb=conn.execute(sqlb)
while not rsb.eof
cid=rsb("id") 
  '商品列表
  m=0
%>
	var arr<%=cid%> = new Array();
	<% 	
	set rs=conn.execute("select id,gname from food_goods where cid="&cid)
	while not rs.eof
	%>
	arr<%=cid%>[<%=m%>] = "<%=rs("id")&","&rs("gname")%>";
	<% 
	m=m+1
	rs.movenext:wend
	rs.close: set rs=nothing
	%>
	
<% 
rsb.movenext:wend
rsb.close:set rsb=nothing
 %>


//当前最大ID值
cid=cid.replace(/\s+/g,"");
var maxid= document.getElementById("ids_"+cid).value;  
maxid=parseInt(maxid)+1;
document.getElementById("ids_"+cid).value=maxid;  
var element = document.createElement("div"); 
element.className="opera clearfix";
element.setAttribute("id",cid+"_"+maxid);

var html="";
html=html+"<div class='w1'>";
html=html+"<div class='dropdown'>";
html=html+"<select name='gid' class='dropdown-select' >";
html=html+"<option value=''>请选择</option>";

for(var i=0;i<eval("arr"+cid).length;i++){
//arr+cid[i] = arr+cid[i];
arrx = eval("arr"+cid)[i].split(",");
html=html+"<option value='"+arrx[0]+"'>"+arrx[1]+"</option>";
}
html=html+"</select>";
html=html+"</div>";
html=html+"</div>";
html=html+"<div class='w2'>";
html=html+"<div class='numtxt'>";
html=html+"<input name='num' type='text' class='inputNum' >";
html=html+"<i class='btn-del' onclick='deleteE(\""+cid+"\",\""+maxid+"\")'></i>";
html=html+"</div>";
html=html+"</div>";

var node = document.createTextNode(""); 
element.appendChild(node); 
x = document.getElementById("buynote_"+cid); 
x.appendChild(element); 
document.getElementById(cid+"_"+maxid).innerHTML = html;
} 

</script>
<i class="btn-del" onclick="deleteE('<%=cid%>','1')"></i>
  • 上一篇文章:JavaScript动态改变HTML页面元素例如添加或删除
  • 下一篇文章:已经没有了
  • 文章评论 (评论内容只代表网友观点,与本站立场无关!)