gpt4 book ai didi

javascript - 使用 jQuery 将值 append 到输入字段

转载 作者:行者123 更新时间:2023-12-03 01:34:40 24 4
gpt4 key购买 nike

我有一个包含三个字段的小表单,我可以在下次提交该表单时选择不同的选项。我正在使用 ajax 调用提交此表单。

现在在表单提交上我想发布所有选定的选项。为此,我创建了一个隐藏字段,例如

<input type="hidden" name="selectedproduct[]" id="sel-product">

和ajax成功方法正在 append 值,例如

 $('#sel-product').val(element.product);

但是这里我只得到一个值而不是一个数组。如何将所有值 append 到该字段?

最佳答案

假设产品字段具有类“.element_product”。

//init the array products
arrp=[];


//loop the elements
$('.element_product').each( function ()
{
arrp.push( $(this).val() );
});

//Pass the array to field
$('#sel-product').val(arrp);

关于javascript - 使用 jQuery 将值 append 到输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51132543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com