关于bootstrap清空表单的两种方法

第一种最直接也相对来说最简便的

$('#模态框的id').on('hidden.bs.modal', function () {

    document.querySelector('#form1').reset();

});

第二种比较繁琐

$(‘#模态框的id').on('hidden.bs.modal',  function () {
		//输入框清空
	$("#表单id  input").each(function(){
 $(this).val('');
})
//下拉菜单清空
$("#表单id select").each(function(){
 //$(this).find("option").remove();
 console.log($(this).find("option").first().prop("selected"))
 $(this).find("option").first().prop("selected",'true').change();
})
//单选框清空
$("#表单id input[type='checkbox']").each(function(){
 this.checked=false
})
//自定义文本清空
$("#表单id textarea").each(function(){
  $(this).val('');
})
});

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值