实现代码如下:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Jquery动态控件</title>
<script src="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" name="text" + i + ""/>
                        <a href="#" class="del-text">del</a></div>');
i++;
} else {
alert("最多只能添加8个");
}
});
$('.del-text').live('click',function(){
$(this).parent().remove();
i--;
});
});
</script>
</head>
<body>
<div id="main">
<div>
<input type="text" name="text1" />
</div>
</div>
<a id="addText" href="#">添加文本框</a>
</body>
</html>

先把前台的整理出来,项目临时有需求,先去忙了,稍后发后台取值的方法...

以上就是【基于Jquery的动态添加控件并取值的实现代码】的全部内容了,欢迎留言评论进行交流!

赞(0) 踩(0)
发表我的评论

最新评论

  1. 暂无评论