美文网首页
清除bootstrap modal缓存的n个思路测试

清除bootstrap modal缓存的n个思路测试

作者: hugoren | 来源:发表于2019-04-07 18:17 被阅读0次

导言

  bootstrap modal具有缓存的功能。
  这功能具有两面性,如果需要这缓存功能,是很好用的。
 不需要这个功能的,去掉缓存,还是有点麻烦的。

去掉缓存的方式

  1. 调用modal的removeData
$("#modal").removeData("bs.modal")

这是清除了modal的值,但输入框上次的值还在

  1. 调用id或name方式
$("#id).val("")

这适用于有id或name,输入框少的情况
如果输入框有十多个需要清除,这种思路就不太合适了

  1. 循环的方式
    (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");

相关文章

网友评论

      本文标题:清除bootstrap modal缓存的n个思路测试

      本文链接:https://www.haomeiwen.com/subject/eubsiqtx.html