【问题标题】:Input fields of form in bootstrap modal is not reset when modal is closed关闭模式时,引导模式中的表单输入字段不会重置
【发布时间】:2023-03-31 13:46:01
【问题描述】:

我在引导模式中有一个表单。第一次它是空的,但是当我第二次打开它时,它仍然包含以前填充的字段。我试过了

<script>
$(function() {
    $('.modal').on('hidden.bs.modal', function(){
        $(this).removeData('bs.modal');
    });
});

但它不起作用

【问题讨论】:

  • 改用$('.modal').on('shown.bs.modal', function(){

标签: javascript twitter-bootstrap bootstrap-modal


【解决方案1】:

你可以做一件事。当您当时关闭模式时,清除输入、文本区域字段。因此,下次您打开模式时,所有字段都将为空。

$('.modal').on('hidden.bs.modal', function (e) {
  $(this)
    .find("input,textarea,select")
       .val('')
       .end()
    .find("input[type=checkbox], input[type=radio]")
       .prop("checked", "")
       .end();
})

http://jsfiddle.net/5LCSU/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多