我有一个带有 4 个文本框的弹出表单,所有文本框在页面加载时都有默认值。
场景如下...用户已在表单中填写了详细信息,但决定不提交表单并关闭弹出窗口。我希望当用户关闭弹出窗口时文本框的值恢复为默认值。
到目前为止,这是我的代码。
$(".close").click( function() {
$(".popup").find("input").val("Default value of textbox");
});
我希望它成为实际的默认值,而不是插入“文本框的默认值”作为值。
I have a popup form with 4 textboxes, all of which have default values when the page loads.
Here's the scenario... The user has filled in the form with their details but decides not to submit the form and closes the popup. I want the values of the textboxes to revert to their default values when the user close the popup.
Here's my code so far.
$(".close").click( function() {
$(".popup").find("input").val("Default value of textbox");
});
Rather than inserting "Default value of textbox" as the value, I want it to be the actual default value.
发布评论
评论(3)
您可以将默认值放在元素本身的“数据属性”中...我将创建一个小提琴来显示这一点... 如 jsFiddle 中所示,
我还应该注意,您可以将数据属性放在服务器上的元素上...我只是展示如何从客户端完成这一切...
You could put the default values in a 'data attribute' on the elements themselves...I'll create a fiddle to show this... As seen in this jsFiddle
I should also note that you can put the data attribute on the elements from the server...I'm just showing how you could do it all from the client...
通过关闭的方式
By way of closure