如何在单击数据关闭按钮时清除引导模式中的所有输入字段? [英] How to clear all input fields in bootstrap modal when clicking data-dismiss button?

查看:151
本文介绍了如何在单击数据关闭按钮时清除引导模式中的所有输入字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何清除Bootstrap V3模式中的所有输入字段,然后单击data-dismiss按钮?

=http://getbootstrap.com/javascript/#modals> http://getbootstrap.com/javascript/#modals 显示隐藏模式时的事件。只需点击即可:

$ $ $ $('#modal1')。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 /






我会建议上述,因为它将清除绑定到模式本身,而不是关闭按钮,但我意识到这并不能解决你的具体问题。你可以使用与解除按钮相同的清除逻辑:

$ $ p $ $''[data-dismiss = modal]')。 on('click',function(e){
var $ t = $(this),
target = $ t [0] .href || $ t.data(target)|| $ t.parents('。modal')|| [];

$(target)
.find(input,textarea,select)
.val(' ')
.end()
.find(input [type = checkbox],input [type = radio])
.prop(checked,)
.end();
})

http://jsfiddle.net/jFyH2/


How to clear all input fields in a Bootstrap V3 modal when clicking the data-dismiss button?

解决方案

http://getbootstrap.com/javascript/#modals shows an event for when a modal is hidden. Just tap into that:

$('#modal1').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/


I would suggest the above as it bind the clearing to the modal itself instead of the close button, but I realize this does not address your specific question. You could use the same clearing logic bound to the dismiss buttons:

$('[data-dismiss=modal]').on('click', function (e) {
    var $t = $(this),
        target = $t[0].href || $t.data("target") || $t.parents('.modal') || [];

  $(target)
    .find("input,textarea,select")
       .val('')
       .end()
    .find("input[type=checkbox], input[type=radio]")
       .prop("checked", "")
       .end();
})

http://jsfiddle.net/jFyH2/

这篇关于如何在单击数据关闭按钮时清除引导模式中的所有输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆