是否可以提交JavaScript数组以及表单提交? [英] Is it possible to submit JavaScript array along with form submission?

查看:109
本文介绍了是否可以提交JavaScript数组以及表单提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Web应用程序创建一个类似列表的表单。元素被添加到列表中,修改和删除,用户点击提交将列表发送到Web应用程序进行进一步处理。

I would like to create a list-like form for a web application. Elements are added to, modified and removed from the list, and the user clicks "Submit" to send the list to the web application for further processing.

我想有两个可以添加数据的 INPUT 字段,单击添加按钮,并将数据添加到DOM(因此用户可以看到它,并删除它通过点击删除按钮)和一个JavaScript数组,将与较大的表单一起提交。在列表建立之前,我不想要任何流量的Web应用程序。

I would like to have two INPUT fields that I can add data into, click an "Add" button, and the data is added to both the DOM (so the user can see it, and remove it by clicking a "Remove" button) and to a JavaScript array that will be submitted along with the larger form. I do not want any traffic to the web application until the list is built.

这是否可行?我的HTML有点生锈,我没有保留最新的JS库。是否有建议用于实现这一点的框架,代码示例?

Is this doable? My HTML is a bit rusty and I haven't kept on top of the latest JS libraries. Are there frameworks you would recommend for accomplishing this, with code samples?

推荐答案

当然可以这样做。

我可以想到一些方法。一个是创建一个将列表项存储在数组中的变量。当您与UI中的列表项目进行交互时,您还可以更新数组。

I can think of a number of ways. One is to create a variable that stores the list items in an array. As you interact with the list items in the UI, you can also updated the array.

点击提交按钮后,将数组保存到隐藏的INPUT中以发回到服务器。

Upon click of the SUBMIT button, stick the array into a hidden INPUT for sending back to the server.

这就是说,如果在UI中快速创建/隐藏事物,一个人可能希望通过AJAX实时更新​​服务器。因此,确保您的UI设计清楚地显示不会更新用户执行SAVE操作。

That said...if things are being created/hidden on the fly in the UI, a person might expect that to be updating the server real-time via AJAX. So make sure your UI design clearly shows that it won't be updated UNTIL a user performs the SAVE action.

对于框架,defacto答案将是jQuery。

As for a framework, the defacto answer would be jQuery.

这篇关于是否可以提交JavaScript数组以及表单提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆