Jquery 将表单输入存储在重写为 doc 的变量中,它们具有原始值
我正在使用 jQuery 为印刷店构建模板表单。用户可以填写表格并单击“预览”按钮。此时,我将表单存储在变量中,并使用 ReplaceWith() 重写文本输入,以将输入从表格单元格中交换出来,并将其替换为其值。 此时,我会显示一个“编辑更多”按钮,以防他们想重新考虑他们的输入。 所以,...然后我将存储变量中的 html 写回到表单中,但令人惊讶的是,文本输入值是用户输入之前的原始默认值。 这是一个相当复杂的项目。我讨厌发布代码,因为我觉得这只会使讨论变得复杂。我希望有人已经有过这种经历,所以知道发生了什么! :-) 谢谢大家。
I am working with jQuery building a Template form for a print shop. Users can fill out the form and click a "Preview" button. At this point, I store the form in a variable and rewrite the text inputs using replaceWith() to swap the input out of the table cell and replace it with its' value.
At this point I show an "Edit More" button in case they want to reconsider their input.
So,... I then write the html in the stored variable back into the form, but surprise, the text input values are the original defaults from before user entry.
This is a pretty complex project. I hate to post code because I feel it will just complicate the discussion. I hope someone has already had this experience so knows just what is up! :-)
Thanks all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解您的要求,我会使用 jQuery 的
.detach() 重写您的一些代码
方法。它允许您将通常要删除的元素存储到变量中,以便稍后可以将它们重新插入回 DOM 中。您仍然可以像常规 jQuery 对象一样与分离的元素进行交互,但您不会在页面上看到它们。
这是一个示例:
作为旁注,发布一些代码通常会有所帮助,因为它可以让每个人更好地了解您要做什么。
If I understand your requirements correctly, I would rewrite some of your code using jQuery's
.detach()
method. It lets you store the elements you would normally be removing into a variable so they can then be reinserted back into the DOM at a later point in time.You will still be able to interact with the detached elements as regular jQuery objects, but you won't see them on the page.
Here's an example:
As a side note, posting some code usually does help as it gives everyone a better idea of what you're trying to do.