简体   繁体   English

取消时取消引导程序模式更改

[英]Dismiss bootstrap modal changes on cancel

I have a bootstrap modal, which has table with attribute contenteditable = true inside of it (table is created dynamically with js). 我有一个引导模式,它的内部具有属性contenteditable = true的表(表是使用js动态创建的)。 I'd like to set up a neat feature - if user presses cancel then the changes in table will be dismissed. 我想设置一个整洁的功能-如果用户按“取消”,则表中的更改将被忽略。 I understand that i could do this with writing a function for different states and then calling out the previous state in case of cancel. 我知道我可以通过为不同状态编写一个函数然后在取消的情况下调出前一个状态来做到这一点。 I'm just thinking that is there a quicker-better-faster approach? 我只是想知道有没有更快更好的方法?

I did some searching and found one link which had similar issue, but the approach and result there are a bit different from mine which means that it didn't work for me. 我进行了一些搜索,发现一个存在类似问题的链接 ,但是方法和结果与我的有所不同,这意味着它对我不起作用。

Here's my code - parts of it are in Estonian, i don't think in general code is necessary for this question but i'll still provide: 这是我的代码-部分代码使用爱沙尼亚语,我认为对于该问题,通用代码不是必需的,但我仍然会提供:

    <div class="modal fade" id="ajamasinModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel"><i class="fa fa-cog" style="font-size:20px"></i> Ajamasin</h4>
                </div>
                <div class="modal-body">
                    <div id="changeablevoor"></div>
                    <button type="button" class="btn btn-primary" onClick="muudaClick()">Change</button>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-success" data-dismiss="modal">Save</button>
                </div>
            </div>
        </div>
    </div> 

Try the following approach ( view comments inline ): 尝试以下方法(查看内联注释):

Html HTML

<div class="modal fade" id="ajamasinModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
     <div class="modal-dialog">
          <div class="modal-content">
               //...
               <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
                    <button type="button" class="btn btn-success" data-dismiss="modal">Save</button>
               </div>
          </div>
      </div>
 </div> 

JS JS

// Add hidden event of the modal 
$('#ajamasinModal').on('hidden.bs.modal', function (e) {
    cancelModal(); // Call the function to cancel the modal after hiding of the modal
})

// Cancel the modal
function cancelModal() {
   // Re-generate content with default values
}

More information about these events of Bootstrap Modal can be found here in the Docs of Bootstrap: Bootstrap Modal Events 有关Bootstrap Modal事件的更多信息,请参见Bootstrap文档: Bootstrap Modal事件。

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

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