亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過selectpicker自動插入輸入表單

通過selectpicker自動插入輸入表單

料青山看我應如是 2023-12-14 16:09:41
我想通過selectpicker自動輸入,然后計算該表單,但下面的代碼不是自動輸入,除非我先單擊輸入表單,計算javascript正在工作,但我想讓輸入價格在我選擇包時自動具有值& 行程無需先點擊輸入表格。抱歉我的英語語法不好,我剛剛開始學習編程。謝謝,這是我的代碼如下:超文本標記語言<label>Package</label><select  onblur="findTotal()" class="selectpicker" id="package">  <option value="" disabled selected>Select package...</option>  <option value="Engagement">Engagement</option>  <option value="Wedding">Wedding</option>  <option value="Other">Other</option></select><br/><label>Trip</label><select  onblur="findTotal()" class="selectpicker" id="trip">  <option value="" disabled selected>Select trip...</option>  <option value="shorttrip">Short Trip</option>  <option value="longttrip">Long Trip</option></select><br/><br/><label>Package Price</label><input onblur="findTotal()" type="text" name="qty" id="packageprice" placeholder="autoinput by selectpicker" /><br/><label>Trip Price</label><input onblur="findTotal()" type="text" name="qty" id="tripprice" placeholder="autoinput by selectpicker" /><br/><label>Tip</label><input onblur="findTotal()" type="text" name="qty" placeholder="manual input"  /><br/><br/><label>Total Price</label><input type="text" name="result" id="total" />腳本語言function findTotal(){    var arr = document.getElementsByName('qty');    var tot=0;    var paket = document.getElementById('package').value;    var trp = document.getElementById('trip').value;        for(var i=0;i<arr.length;i++){        if(parseInt(arr[i].value))            tot += parseInt(arr[i].value);    }        if (paket == "Engagement") {        document.getElementById('packageprice').value = "1000";    } else if (paket == "Wedding") {      document.getElementById('packageprice').value = "2000";    } else {      document.getElementById('packageprice').value = "0";    }或者您可以在此處查看 JS Fiddle 上的代碼: http: //jsfiddle.net/ryh7vpwa/5/
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

您應該在實現 findTotal 函數的元素上使用oninput而不是onblur


<select  oninput="findTotal()" class="selectpicker" id="package">

  <option value="" disabled selected>Select package...</option>

  <option value="Engagement">Engagement</option>

  <option value="Wedding">Wedding</option>

  <option value="Other">Other</option>

</select>


<br/>


<label>Trip</label>

<select  oninput="findTotal()" class="selectpicker" id="trip">

  <option value="" disabled selected>Select trip...</option>

  <option value="shorttrip">Short Trip</option>

  <option value="longttrip">Long Trip</option>

</select>


查看完整回答
反對 回復 2023-12-14
  • 1 回答
  • 0 關注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號