导言
bootstrap modal具有缓存的功能。
这功能具有两面性,如果需要这缓存功能,是很好用的。
不需要这个功能的,去掉缓存,还是有点麻烦的。
去掉缓存的方式
- 调用modal的removeData
$("#modal").removeData("bs.modal")
这是清除了modal的值,但输入框上次的值还在
- 调用id或name方式
$("#id).val("")
这适用于有id或name,输入框少的情况
如果输入框有十多个需要清除,这种思路就不太合适了
- 循环的方式
(1) 不带name的方式
//清除modal输入框的值
$modal.find('input').each(function () {
$(this).val("")
});
$modal.find('select').each(function () {
$(this).val("")
});
$modal.find('textarea').each(function () {
$(this).val("")
});
(2)带name 方式
$modal.find('input[name]').each(function () {
$(this).val("")
});
$modal.find('select[name]').each(function () {
$(this).val("")
});
$modal.find('textarea[name]').each(function () {
$(this).val("")
});
总结:
如果是form 或其它组件, 如ncform,可以尝试reset,我测试过,reset或赋对象为空,组件还是上次的值
如:
//this.$data.formSchema.value = {}
//this.$ncformReset("form-1");
网友评论