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

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

單擊函數(shù)不使用 append() 函數(shù)附加 HTML 塊

單擊函數(shù)不使用 append() 函數(shù)附加 HTML 塊

HUH函數(shù) 2023-06-15 09:37:11
我試圖在點(diǎn)擊時(shí)再次附加相同的代碼。我的“education_wrap”類現(xiàn)在是空的。除此之外,我現(xiàn)在剛剛添加了內(nèi)聯(lián) CSS。var max_fields = 5; //maximum input boxes allowedvar wrapper = $(".education_wrap"); //Fields wrappervar add_button = $("#add_education"); //Add button ID    $(add_button).click(function(e){    e.preventDefault();    var total_fields = wrapper[0].childNodes.length;    if(total_fields < max_fields){        $(wrapper).append('<p style="font-weight:bold;">Institute Name<span class="required">*</span></p><div class="item"><input type="text" id="institute" name="institute" placeholder="Institute Name" required/></div><p style="font-weight:bold;">Degree Name<span class="required">*</span></p><div class="item"><input type="text" id="degree" name="degreen" placeholder="Bachelor of Engineering in Software Engineering, etc." required/></div><p style="font-weight:bold;">From<span class="required">*</span></p><div class="item"><input type="date" id="from_date" name="from_date" value="2020-07-22" required/></div><p style="font-weight:bold;">To<span class="required">*</span></p><div class="item">                    <input type="date" id="to_date" name="to_date" value="2020-07-22" required/></div></div>'); //add input box      }});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <form><h3 style="font-weight: bold;">Education</h3>        <div class="education_wrap">        <p style="font-weight:bold;">Institute Name<span class="required">*</span></p>          <div>                                <input type="text" id="institute" name="institute" placeholder="Institute Name" required/>          </div>另外,我無法理解如何使用 POST 方法一次提交多組信息。請(qǐng)指導(dǎo)。
查看完整描述

2 回答

?
慕桂英546537

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

var max_fields = 5; //maximum input boxes allowed

var wrapper = $(".education_wrap"); //Fields wrapper

var add_button = $("#add_education"); //Add button ID


$(add_button).click(function(e) {

  var total_fields = wrapper[0].childNodes.length;

  alert(total_fields < max_fields);

  //if (total_fields < max_fields) { // this condition returns false that's why it creates issue

    $(wrapper).append('<p style="font-weight:bold;">Institute Name<span class="required">*</span></p><div class="item"><input type="text" id="institute" name="institute" placeholder="Institute Name" required/></div><p style="font-weight:bold;">Degree Name<span class="required">*</span></p><div class="item"><input type="text" id="degree" name="degreen" placeholder="Bachelor of Engineering in Software Engineering, etc." required/></div><p style="font-weight:bold;">From<span class="required">*</span></p><div class="item"><input type="date" id="from_date" name="from_date" value="2020-07-22" required/></div><p style="font-weight:bold;">To<span class="required">*</span></p><div class="item">                    <input type="date" id="to_date" name="to_date" value="2020-07-22" required/></div></div>'); //add input box

  //}

});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<form>

  <h3 style="font-weight: bold;">Education</h3>

  <div class="education_wrap">

    <p style="font-weight:bold;">Institute Name<span class="required">*</span></p>

    <div>

      <input type="text" id="institute" name="institute" placeholder="Institute Name" required/>

    </div>

    <p style="font-weight:bold;">Degree Name<span class="required">*</span></p>

    <div>

      <input type="text" id="degree" name="degreen" placeholder="Bachelor of Engineering in Software Engineering, etc." required/>

    </div>

    <p style="font-weight:bold;">From<span class="required">*</span></p>

    <div>

      <input type="date" id="from_date" name="from_date" value="2020-07-22" required/>

    </div>

    <p style="font-weight:bold;">To<span class="required">*</span></p>

    <div>

      <input type="date" id="to_date" name="to_date" value="2020-07-22" required/>

    </div>

  </div>

  <div style="margin-top:20px;">

    <button type="submit" id="add_education">Add Another Education</button>

  </div>

</form>

注意:- 您的代碼中有一個(gè)小錯(cuò)誤。有一個(gè) if 條件返回一個(gè)假值,這就是為什么代碼塊沒有被執(zhí)行的原因。



查看完整回答
反對(duì) 回復(fù) 2023-06-15
?
慕森卡

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

您的代碼中有很多問題,請(qǐng)遵循以下事項(xiàng):

1. if(total_fields < max_fields){在這里您的條件變得錯(cuò)誤,因此不會(huì)append開始任何過程

2. 使用type="button"而不是submit

3. 使用單獨(dú)的按鈕進(jìn)行追加htmlsubmit表單

如何使用 POST 提交多組信息

使用輸入名稱作為數(shù)組<input type="date" id="from_date" name="from_date[]" value="2020-07-22" required/>

因?yàn)檫@里重復(fù)所以使用classes而不是這里idid="from_date"


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

添加回答

舉報(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)