jquery无刷新添加和删除input输入框 增加减少input框
2017-05-31 20:38
441 查看
一、页面代码
<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>
二、脚本
<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
<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>
二、脚本
<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
相关文章推荐
- jquery无刷新添加和删除input输入框 增加减少input框
- jquery无刷新添加和删除input输入框
- jquery 实现表格内的tr与td,动态添加与删除. 以及序号增加与减少,大多用在Form里
- jquery添加和删除多个同名的input输入框
- 通过cloneya无刷新动态添加或减少多个input输入框前后台代码实现
- jQuery实现动态添加、删除按钮及input输入框的方法
- 基于Bootstrap使用jQuery实现输入框组input-group的添加与删除-改进版
- 基于Bootstrap使用jQuery实现输入框组input-group的添加与删除
- jQuery Tags Input Plugin(添加/删除标签插件)详解
- 添加可动态变化的输入框,点击添加增加一行,点击删除删除一行
- 点击复选框添加或删除value值到input输入框中
- jQuery Tags Input Plugin(添加/删除标签插件)
- Jquery实现table行数的增加,删除,实现指定行数的添加等应用~~~~!!!!
- jquery 动态增加,减少input表单的简单方法(必看)
- 基于Bootstrap使用jQuery实现输入框组input-group的添加与删除
- 项目经验之:利用Jquery+HTML静态模版实现数据的展示及无刷新增加,修改,删除,分页操作!!!
- jQuery Tags Input Plugin(添加/删除标签插件)
- javascript动态添加、删除按钮和input输入框
- jQuery无刷新翻页,更改排序,同时带添加,修改,删除数据
- JQuery中对Select的option项的添加、删除、取值(带输入框)