简体   繁体   English

取消按钮在jQuery中不起作用

[英]Cancel button is not working in jQuery

Tried to implement edit, save, cancel in collapsible accordion. 尝试在可折叠的手风琴中执行编辑,保存,取消。 Everything is working fine. 一切正常。 Data is passing and data is saving. 数据正在传递,数据正在保存。 Cancel button is not working. 取消按钮不起作用。 When user not willing to save the data he must cancel and go back to first state of the form. 当用户不愿意保存数据时,他必须取消并返回到表单的第一状态。 I used glyphicons instead of buttons and used jquery functions to achieve the requirement but cancel is not happening. 我使用glyphicons而不是按钮,并使用jquery函数来达到要求,但取消并没有发生。

 <div class="col-md-6"> <div class="panel panel-default"> <div class="panel-heading" style="background-color: #b3daff;"> <h4 class="panel-title"> <span style="font-weight: 700;">Address Details</span>&nbsp;&nbsp; <a class="editAddBtn"><span class="glyphicon glyphicon-pencil">&nbsp;</span></a> <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree"> <span class="glyphicon glyphicon-plus" id="pls" style="color: darkred">&nbsp;</span> </a> </h4> </div> <div id="collapseThree" class="panel-collapse collapse"> <div class="panel-body"> <div class="col-sm-4 col-md-12"> <div class="row"> <div class="form-group"> <label class="control-label col-sm-12 col-md-8">Current </label> </div> </div> </div> <script> $(document) .ready( function() { $('.editAddBtn') .click( function() { if ($('.editField').is( '[readonly]')) { //checks if it is already on readonly mode $('.editField').prop( 'readonly', false); //turns the readonly off $('.mySelect').prop( 'disabled', false); $('#chk').prop('disabled', false); $('.editAddBtn') .html( '<span class="glyphicon glyphicon-floppy-disk">&nbsp;</span><span id="removeBtn" class="glyphicon glyphicon-repeat">&nbsp;</span>'); //Changes the text of the button } else { //else we do other things saveAddress(); $('.editField').prop( 'readonly', true); $('.mySelect').prop( 'disabled', true); $('#chk').prop('disabled', true); $('.editAddBtn') .html( '<span class="glyphicon glyphicon-pencil">&nbsp;</span>'); $('#removeBtn').on('click', function(e) { e.preventDefault(); window.history.back(); }); } }); }); } </script> 

In this case i would use CSS/HTML to hide/show different states in your application. 在这种情况下,我将使用CSS / HTML隐藏/显示应用程序中的不同状态。 I think the DOM bindings are messing up, since you are changing HTML with javascript. 我认为DOM绑定很混乱,因为您正在使用javascript更改HTML。

When user goes in to editing mode, then hide the notEditing class and show isEditing . 当用户进入编辑模式时,然后隐藏notEditing类并显示isEditing

<div class="col-md-6">
  <div class="panel panel-default">
    <div class="panel-heading" style="background-color: #b3daff;">
      <h4 class="panel-title">
        <span style="font-weight: 700;">Address Details</span>&nbsp;&nbsp;
        <span class="notEditing">
          <a class="editAddBtn"><span
           class="glyphicon glyphicon-pencil">&nbsp;</span></a>
        </span>
        <span class="isEditing">
          <span class="glyphicon glyphicon-floppy-disk">&nbsp;</span><span id="removeBtn" class="glyphicon glyphicon-repeat">&nbsp;</span>
        </span>
        <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree"> <span class="glyphicon glyphicon-plus" id="pls" style="color: darkred">&nbsp;</span>
        </a>
      </h4>
    </div>

If its ok for you to just reset by refreshing the page, then do that. 如果可以通过刷新页面进行重置,可以这样做。 If not, then you should save form state, when the user is entering editing mode. 如果不是,那么当用户进入编辑模式时,您应该保存表单状态。

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

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