[英]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.