jQuery SerializeArray/Param 获取类名?
我有一个表单,其中隐藏了实时附加输入类型,其中包含名称、值和类,它们都有意义。我想把这个并将 json 值发布到我的 php 中。所以我正在这样做
var storage = $.param($('form input[type=hidden]').serializeArray(), true);
,效果很好,但它只获得名称和值。我还需要该类,因为它存储了一个唯一的 id,但我无法将其存储在名称或值中,因为它们也存储唯一的 id。
所以我的问题/选择是。
- 我可以以某种方式在名称中存储两个唯一的 id 吗?也许是
{id1:1,id2:2}
或其他名称值? - 我可以让serializeArray也获取类名吗?
输入类型隐藏的示例我添加
注意名称和班级末尾有两个不同的 id。
I have a form that had live appended input type hiddens with a name, value, and class and they all mean something. I want to take this and post to my php the json values. So I am doing
var storage = $.param($('form input[type=hidden]').serializeArray(), true);
and that works fine, however it only gets the name, and value. I need the class also because it has a unique id stored in it, which I can't store in the name or value because those also store unique ids.
So my question/options are.
- Can I somehow store two unique ids in the name that would be processed as such? Maybe a
{id1:1,id2:2}
or something as the name value? - Can I make serializeArray also get the class name?
Example of input type hidden I add
<input type="hidden" class="photo_spot_1" name="photo_spot_5" value="../uploads/2462df38db374653720daa42b7aefec4/g6qjcn30kw_c.png">
Notice the two different id's at the end of name and class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能拥有像
{id1:1,id2:2}
这样的元素 id,并且serializeArray
也不会从输入字段获取类信息,但您可以编写自己的逻辑明白了。现在您可以使用
data
,它将包含每个隐藏输入的名称/值和类信息。You cannot have an element id like
{id1:1,id2:2}
and alsoserializeArray
will not get the class information from input fields but you can write your own logic to get that.Now you can use
data
which will contain each hidden input with is name/value and class information.您最好的选择可能是采用这些独特的类,并在序列化表单并发布帖子之前将它们放入隐藏的输入中。这将使您的服务器端代码更容易访问这些值。
像这样的事情:
Your best bet will likely be to take those unique classes, and throw them onto a hidden input before you serialize your form and do your post. This will give your server side code much easier access to these values.
Something like this: