简体   繁体   English

关闭对话框时,如何使对话框不保存对对话框所做的任何更改?

[英]How do I make the dialog not save any changes I made to inside it when I close it?

I'm using JQuery UI Dialog, and I can't seem to make it ignore any changes made to the value when closing. 我正在使用JQuery UI对话框,似乎无法使其在关闭时忽略对该值所做的任何更改。 When I open the dialog, make any changes to and then close it, then it should refresh the dialog to what it was before when I open the dialog again. 当我打开对话框时,对其进行任何更改,然后将其关闭,然后它将刷新该对话框,使其与我再次打开该对话框之前的状态相同。 I'm using $('#profile_content').dialog() , where profile_content is the id for the div block: 我正在使用$('#profile_content').dialog() ,其中profile_content是div块的ID:

<div id='profile_content'>
 <label for="user_name">Name:</label>
 <input type="text" id="user_name" value="<?php echo $user['username'] ?>"/><br>
 <label for="user_email">Email:</label>
 <input type="text" id="user_email" value="<?php echo $user['email'] ?>"/>
</div>

It's just a <div> that's shown and hidden appropriately. 只是适当显示和隐藏的<div> What I usually do is clear all values during close or open. 我通常要做的是清除关闭或打开期间的所有值。 You can have a function bound to these events. 您可以将一个函数绑定到这些事件。

You could do something like this. 你可以做这样的事情。

In your fields you implement a "data" property. 在您的字段中,实现“数据”属性。

<input type="text" id="user_name" data-default-value="<?php echo $user['username'] ?>"/>

Then on open of the dialog you call this, which sets it back to the default value: 然后,在打开对话框时将其命名为默认值:

$("#profile_content input").each(function() {
   $(this).val($(this).data("default-value"));
}

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

相关问题 如何让 php 知道我在输入中进行了更改? - How do I let php know that I made changes In input? 从一页转到下一页时,如何保存所做的标记更改? - How do I save the markup change I made, when going from one page to the next? 我在wordpress父主题中对模板文件进行了一些自定义更改。 如何确保主题更新时它们不会被覆盖? - I made some custom changes to template files in my wordpress parent theme. How do i make sure they are not overwritten when theme gets updated? 我如何在网页上存储由javascript所做的更改? - How do I have a web page store changes made by javascript? 如何使JQuery关闭按钮? - How do I make a JQuery close a button? 如何在关闭的对话框中删除选定的元素/文本? - How do I remove selected elements/text in a dialog on close? 每次进行更改时,我真的必须重新启动服务器吗? - Do i really have to restart the server everytime i made changes? 当用户关闭任何特定选项卡时如何显示提示? (这是关于单个选项卡,而不是所有浏览器的) - How do i show prompt when user close any particular tab? (This is about individual tab not for all browser) 如何从iframe中的onclick事件关闭iframe? - How do I close an iframe from an onclick event inside the iframe? 当用户关闭浏览器时,如何使我的网站自动注销? - How do I make my site automatically sign out a user when they close their browser?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM