从表单实时更新数据
我有一个动态表单,用户可以输入收据数据。我试图克隆他们在一个单独的 div 上输入的内容,该 div 的设计看起来像他们输入的收据。我想显示文本的值并将元素选择到该单独的 div 中。
我试图在 jquery 中做到这一点。有人有例子吗?
编辑
问题是我不知道如何获取 div id,因为它是动态生成的。
I have a dynamic form that users enter receipt data. I'm trying to clone what they're inputting on a separate div that is designed to look like the receipt they're inputting. I want to display the values of the text and select elements into that separate div.
I was trying to do this in jquery. Does anyone have an example?
edit
The issue is that I don't know how to fetch the div id because it's being generated dynamically.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用 keyup 事件。假设您像这样设置输入字段和 div:
您可以在 jQuery 中执行以下操作:
稍后可以通过为receipt_no keyup 和其他表单元素的更改事件(例如下拉列表)添加通用函数来使其变得更复杂。您只需使用预览所需的所有元素来构造 Preview_text 即可。
I would suggest using a keyup event. Assuming you set up your input field and divs like so:
You could do the following in jQuery:
You can make it more complex later on by adding a common function for the receipt_no keyup and other form elements' change events (e.g. a dropdown). You just have to construct the preview_text using all the elements you need for the preview then.
这是一个简单的示例:
HTML:
js:
Here is a simple sample:
HTML:
js: