第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何獲取數(shù)組后值

如何獲取數(shù)組后值

蕪湖不蕪 2023-07-06 14:37:33
在我的腳本中,我有動(dòng)態(tài)添加的輸入字段。我必須使用 php 獲取所有輸入值,但 $_POST['poids'] 中的問題只給我輸入數(shù)組的第一個(gè)值,因此只給我數(shù)組 poids 的第一個(gè)元素。這是我的代碼:$(function() {  var max_fields = 10;  var $wrapper = $(".container1");  var add_button = $(".add_form_field");  $(add_button).click(function(e) {    e.preventDefault();    const vals = $("> .item input[name^=poids]", $wrapper).map(function() {      return +this.value    }).get()    const val = vals.length === 0 ? 0 : vals.reduce((a, b) => a + b);    if ($("> .item", $wrapper).length < max_fields && val < 100) {      const $form_colis = $(".item").first().clone();      $form_colis.find("input").val("");      $wrapper.append($form_colis); //add input box    } else {      var err_msg = 'limit riched';      //alert(err_msg);      window.alert(err_msg);    }  });  $wrapper.on("click", ".delete", function(e) {    e.preventDefault();    $(this).parent('div').remove();  })});<div class="container1" style="min-height:200px">  <button class="add_form_field">Add New Field ?</button>  <form method="post" action="postForm.php">    <div class="item">      <input type="text" placeholder="Poids" name="poids[]">      <input type="text" placeholder="Longueur" name="longueurs[]">      <input type="text" placeholder="Largeur" name="largeurs[]">      <input type="text" placeholder="Hauteur" name="hauteurs[]">      <a href="#" class="delete">Delete</a>    </div>    <button type="submit" name="" class="btn btn-danger btn-responsive "> Send </button></center>    </a>  </form></div>獲取帖子(postForm.php):$poids = $_POST['poids'];foreach($poids as $poid) {    echo " -->" .$poid;}我希望你明白我的意思。先感謝您
查看完整描述

2 回答

?
慕碼人8056858

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊

問題是您將帶有新輸入字段的 div 附加到$wrapper,但這在表單之外。您需要將其放入表格中。

改變

      $wrapper.append($form_colis); //add input box

      $('.item', $wrapper).last().after($form_colis); //add input box


查看完整回答
反對(duì) 回復(fù) 2023-07-06
?
神不在的星期二

TA貢獻(xiàn)1963條經(jīng)驗(yàn) 獲得超6個(gè)贊

我不是 PHP 專家,但通過瀏覽提供的代碼,您似乎只是在搜索名稱值為 poids 的輸入。


const vals = $("> .item input[name^=poids]",$wrapper).map(function() { return +this.value }).get()

然后,當(dāng)您創(chuàng)建 bew 輸入時(shí),您不會(huì)將 poids 附加到輸入名稱。


const $form_colis = $(".item").first().clone();

                  $form_colis.find("input").val("");

                  $wrapper.append($form_colis);

因此,用你的方法你只會(huì)找到一個(gè),那就是這個(gè):


   <input type="text" placeholder="Poids" name="poids[]">

因此,為了解決這個(gè)問題,在$form_colis方法內(nèi)部添加poids我相信的內(nèi)容。


查看完整回答
反對(duì) 回復(fù) 2023-07-06
  • 2 回答
  • 0 關(guān)注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)