简体   繁体   English

取消将初始单击功能绑定到另一个按钮上的单击

[英]unbind the initial click function on another button click

I have a form which is initially hidden. 我有一个最初被隐藏的表格。 There is two steps of click flow to reach the form. 点击流程有两个步骤可以到达表单。 I need to reset the initial click action when the form close button is clicked. 单击表单关闭按钮时,我需要重置初始单击动作。

Adding the sample code and demo. 添加示例代码和演示。

Here goes the flow 流程在这里

  • Click on the Join Now text 单击Join Now文本
  • Then click on the text Click here to open the form text 然后单击文本Click here to open the form文本
  • Then click on the close icon 然后点击close图标
  • There comes the pop up 弹出来了

What I now need to know is, 我现在需要知道的是

  1. By clicking on Yes , the form needs to be reset and the screen should look like how it looked initially (Brand name box with join now text) and the initial click action of join now should be refreshed. 通过单击“ Yes ,需要重置表单,并且屏幕应该看起来像最初的样子(带有“立即join now文本的品牌框),并且应该刷新“ join now的初始单击操作。

  2. By clicking on No , it should remain on the same form. 通过单击No ,它应该保留在同一表格上。

      $(".button").click(function(e){ e.preventDefault(); $(this).hide(); $(".slidethis").fadeIn(800).css("display","inline-block"); $(".wrapper").css("display","block"); }); $(".seconddiv").hide(); //forstdiv click $(".firstdiv").click(function(){ $(this).hide(); $(".seconddiv").show(); }); //Close button $(".close_icon").click(function(){ $(".popup").show(); }); 

Demo Here 在这里演示

PS: I don't want to refresh the page by closing the form. PS:我不想通过关闭表单来刷新页面。

Adding this code should do it. 添加此代码即可。 It's about reversing your steps: 这是关于反转您的步骤:

$("input[value=Yes]").click(function(){
    //reset - reverse all the steps
    $(".button").show();
    $(".slidethis").fadeOut(800).css("display","none");
    $(".wrapper").css("display","inline-block");
    $(".popup").hide();
    $(".seconddiv").hide();
    $(".firstdiv").show();
});


$("input[value=No]").click(function(){
   $(".popup").hide();

}); 

Updated fiddle: https://jsfiddle.net/5353ntuf/5/ 更新的提琴: https : //jsfiddle.net/5353ntuf/5/

Working fiddle . 工作提琴

You should add an event click on the both buttons Yes and No , so give them a common class , eg confirm class: 您应该在两个按钮“ Yes和“ No上单击添加一个事件,因此给它们一个通用的类,例如, confirm类:

<input type="button" class='confirm' value="Yes" />
<input type="button" class='confirm' value="No" />

Then add a condition to check which action you're going to perform, like : 然后添加一个条件来检查您将要执行的操作,例如:

//Confirm buttons
$("body").on("click", ".confirm", function() {
  $(".popup").hide();

  if ($(this).val() == 'No') 
  {
    $('form input').val(""); //Reset form
  } else {
    $(".seconddiv,.slidethis").hide();
    $(".firstdiv,.button").show();
    $(".wrapper").css("display", "inline-block");
  }
});

Hope this helps. 希望这可以帮助。

 //slide open the main panel $(".button").click(function(e) { e.preventDefault(); $(this).hide(); $(".slidethis").fadeIn(800).css("display", "inline-block"); $(".wrapper").css("display", "block"); }); $(".seconddiv").hide(); //forstdiv click $(".firstdiv").click(function() { $(this).hide(); $(".seconddiv").show(); }); //Close button $(".close_icon").click(function() { $(".popup").show(); }); //Confirm buttons $("body").on("click", ".confirm", function() { $(".popup").hide(); if ($(this).val() == 'No') { $('form input').val(""); } else { $(".seconddiv,.slidethis").hide(); $(".firstdiv,.button").show(); $(".wrapper").css("display", "inline-block"); } }); 
 .wrapper { background: #9ac366; display: inline-block; } .headcard { display: inline-block; text-align: center; padding: 3% 30px; float: left; } .slidethis { background: #b67fd8; padding: 20px 0; width: 70%; vertical-align: top; position: relative; height: 228px; display: none; position: relative } .firstdiv, .seconddiv { width: 200px; border: #888 solid 2px; padding: 20px; } .close_icon { background: #333; color: #fff; padding: 4px; float: right; margin-top: -20px; text-decoration: none } .popup { position: absolute; top: 0; bottom: 0; right: 0; left: 0; background: #e4e4e4; text-align: center; padding-top: 5%; display: none } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="wrapper"> <div class="headcard"> <h4>Brand Name</h4> <a href="#" class="button">Join Now </a> </div> <!--this is hidden by default--> <div class="slidethis"> <div class="firstdiv"> Click here to open the form </div> <div class="seconddiv"> <form> <a href="#" class="close_icon">X</a> <input placeholder="name" /> <input placeholder="email" /> </form> <!--close pop up--> <div class="popup"> Closing will clear the form data. Do you want ot close? <br/> <input type="button" class='confirm' value="Yes" /> <input type="button" class='confirm' value="No" /> </div> </div> </div> </div> 

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

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