我使用的是JQuery UI对话框,在关闭时似乎不能让它忽略对值所做的任何更改。当我打开对话框,对其进行任何更改,然后关闭它时,当我再次打开对话框时,它应该会将对话框刷新为以前的状态。我使用的是$('#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>
它只是一个适当显示和隐藏的<div>
。我通常做的是在关闭或打开时清除所有值。您可以将函数绑定到这些事件。
您可以这样做。
在字段中,您实现了一个"数据"属性。
<input type="text" id="user_name" data-default-value="<?php echo $user['username'] ?>"/>
然后在打开对话框时,您调用它,这会将其设置回默认值:
$("#profile_content input").each(function() {
$(this).val($(this).data("default-value"));
}