簡體   English   中英

使用jQuery將值附加到輸入字段

[英]Append value to input field using jQuery

我有一個包含三個字段的小表格,下次我可以提交該表格,選擇其他選項。 我正在使用ajax電話提交此表格。

現在在表單提交中,我要發布所有選定的選項。 為此,我創建了一個隱藏字段,例如

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

和ajax成功方法正在附加像

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

但是在這里,我只得到一個值,而不是數組。 如何將所有值附加到字段?

假設產品字段的類別為“ .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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM