基于Jquery的动态添加控件并取值的实现代码,需要的朋友可以参考下。
复制代码 代码如下:
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>Jquery动态控件</title> 
<script src="https://www.jb51.net/jquery-1.4.2.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(function() { 
var i = 2; 
$('#addText').click(function() { 
if (i < 9) { 
$('#main').append('<div><input type="text" + i + ""/> 
                        <a href="#">del</a></div>'); 
i++; 
} else { 
alert("最多只能添加8个"); 
} 
}); 
$('.del-text').live('click',function(){ 
$(this).parent().remove(); 
i--; 
}); 
}); 
</script> 
</head> 
<body> 
<div> 
<div> 
<input type="text" /> 
</div> 
</div> 
<a href="#">添加文本框</a> 
</body> 
</html> 
先把前台的整理出来,项目临时有需求,先去忙了,稍后发后台取值的方法...
