jquery无刷新添加和删除input输入框 增加减少input框

XML/HTML Code
- <a href="#" id="AddMoreFileBox" class="btn btn-info">添加更多的input输入框</a></span></p>
- <div id="InputsWrapper">
- <div><input type="text" name="mytext[]" id="field_1" value="Text 1"/><a href="#" class="removeclass">×</a></div>
- </div>
JavaScript Code
- <script>
- $(document).ready(function() {
- var MaxInputs = 8; //maximum input boxes allowed
- var InputsWrapper = $("#InputsWrapper"); //Input boxes wrapper ID
- var AddButton = $("#AddMoreFileBox"); //Add button ID
- var x = InputsWrapper.length; //initlal text box count
- var FieldCount=1; //to keep track of text box added
- $(AddButton).click(function (e) //on add input button click
- {
- if(x <= MaxInputs) //max input box allowed
- {
- FieldCount++; //text box added increment
- //add input box
- $(InputsWrapper).append('<div><input type="text" name="mytext[]" id="field_'+ FieldCount +'" value="Text '+ FieldCount +'"/><a href="#" class="removeclass">×</a></div>');
- x++; //text box increment
- }
- return false;
- });
- $("body").on("click",".removeclass", function(e){ //user click on remove text
- if( x > 1 ) {
- $(this).parent('div').remove(); //remove text box
- x--; //decrement textbox
- }
- return false;
- })
- });
- </script>
原文地址:http://www.freejs.net/article_biaodan_278.html
最近更新
- 响应式全屏手风琴菜单,同时支持垂直方...
- 分组select选择器,支持多选和单...
- jQuery时间日期选择器代码日历插...
- Select 选择器 可以清空的单选...
- jQuery json 无刷新翻页 ...
- 纯css3带倒影效果的图片翻转特效
我爱薅羊毛
点击最多
广告赞助
相关文章
- 美化input radio select等输入框,...
- select 下拉框多选,用select代替che...
- jQuery下拉多选插件 下拉框复选 包括全选
- radio单选框彩色,自定义边框,圆点颜色和大小
- 自定义checkbox和radio样式 圆形方形...
- select下拉菜单带图片