简体   繁体   English

在“ mfp-close”中以清晰的形式显示弹出式窗口

[英]Clear form on `mfp-close` in magnific popup

I am trying to clear all the errors and make input values blank on closing of magnific popup. 我正在尝试清除所有错误,并在关闭大型弹出窗口时使输入值空白。

I inspected the class of 'close' button and tried to fire jquery event but it is not working. 我检查了“关闭”按钮的类,并尝试触发jquery事件,但是它不起作用。

$("button.mfp-close").on('click',function(){
  console.log("Closed");
});

When i click on mfp-close then there is no log in console. 当我单击mfp-close ,控制台中没有登录。

HTML snippet is: HTML代码段是:

    <div class="mfp-content"><div id="customdesign" class="white-popup mfp-with-anim">
    <div class="row">
        <div class="col-sm-12 text-center"> 
        <h3>Upload Your Design</h3>
        <p><span class="success_sbmt" style="display:none;color:green">Congratulations! We have sent you the coupon code on your registered email id</span>
        </p><form novalidate="novalidate" class="form cmxform" id="customForm">
        <input name="leave" value="http://" type="hidden">
        <input name="isblank" value="" type="hidden">
        <div class="form-group">
        <label class="sr-only">Name</label>
        <input aria-required="true" class="form-control" name="nam_cst" id="nam_cst" 
     placeholder="Enter Name.." required="" type="text">
        <span class="help-block" style="color:red"></span>
     </div>
    </form>
</div>
</div>
<button title="Close (Esc)" type="button" class="mfp- close">×</button>       
</div></div>

How can we handle this operation?? 我们如何处理此操作?

First of all, if you are using bootstrap framework, use bootstrap modal instead magnific popup, no need for extra js librabry, you can achieve same with bootstrap modal 首先,如果您使用的是Bootstrap框架,请使用bootstrap modal而不是壮观的弹出窗口,不需要额外的js librabry,您可以使用bootstrap modal来实现

in your HTML, button you have class="mfp- close" it should be class="mfp-close" as you are binding it like this $("button.mfp-close") 在您的HTML中,按钮具有class="mfp- close" class="mfp-close" ,它应为class="mfp-close"因为您需要像$("button.mfp-close")这样进行绑定

To reset form on pop-up close, you can achieve it with $('form')[0].reset(); 要在弹出窗口关闭时重置表单,可以使用$('form')[0].reset();

Script 脚本

$("button.mfp-close").on('click',function(){
    alert("Closed");
    $('form')[0].reset();
});

HTML HTML

<a class="popup-modal" href="#customdesign">Open modal</a>

<div class="mfp-content">
<div id="customdesign" class="white-popup-block mfp-hide">
<div class="row">
    <div class="col-sm-12 text-center"> 
        <h3>Upload Your Design</h3>
        <p>
            <span class="success_sbmt" style="display:none;color:green">Congratulations! We have sent you the coupon code on your registered email id</span>
        </p>
        <form novalidate="novalidate" class="form cmxform" id="customForm">
        <input name="leave" value="http://" type="hidden">
        <input name="isblank" value="" type="hidden">
        <div class="form-group">
            <label class="sr-only">Name</label>
                <input aria-required="true" class="form-control" name="nam_cst" id="nam_cst" placeholder="Enter Name.." required="" type="text">
                <span class="help-block" style="color:red"></span>
        </div>
        </form>
    </div>
</div>
<button title="Close (Esc)" type="button" class="mfp-close">×</button>       
</div>
</div>

Working fiddle example 工作小提琴的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM