zl程序教程

您现在的位置是:首页 >  前端

当前栏目

基于Jquery的动态添加控件并取值的实现代码

jQuery代码 实现 基于 添加 动态 控件 取值
2023-06-13 09:14:24 时间
复制代码代码如下:

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Jquery动态控件</title>
<scriptsrc="jquery-1.4.2.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(function(){
vari=2;
$("#addText").click(function(){
if(i<9){
$("#main").append("<div><inputtype="text"name="text"+i+""/>
                        <ahref="#"class="del-text">del</a></div>");
i++;
}else{
alert("最多只能添加8个");
}
});
$(".del-text").live("click",function(){
$(this).parent().remove();
i--;
});
});
</script>
</head>
<body>
<divid="main">
<div>
<inputtype="text"name="text1"/>
</div>
</div>
<aid="addText"href="#">添加文本框</a>
</body>
</html>

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