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

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

如何使用按鈕輸入的金額和總金額重置特定輸入字段?

如何使用按鈕輸入的金額和總金額重置特定輸入字段?

千萬里不及你 2021-11-25 15:27:02
我有一個用于特定字段的工作總和和重置按鈕,僅在不在表單標簽內時才有效,但我需要將所有輸入字段和金額按鈕放在表單標簽內,以便在提交之前進行驗證。過程應該是這樣的:-當客戶點擊指定金額的多個按鈕時,總金額將顯示在一個字段上。- 當客戶點擊重置時,應重置特定字段。但問題是,當字段上顯示的總金額被重置時,客戶再次單擊按鈕,金額只會添加到已清除的總金額中。但是當我刪除表單標簽時,重置按鈕實際上正在工作,但提交按鈕上的驗證將不起作用。那么,如果我不刪除表單標簽,還有什么替代方法呢?我的代碼和 jsfiddle 附在下面://Total Amount Sum Calculatorvar sum = 0;function f(val){  sum += val;  document.getElementById("deposit-total").value = sum;}function reset(){  sum = 0;  document.getElementById("deposit-total").value = 0;}//Automatic Commafunction FormatCurrency(ctrl) {            //Check if arrow keys are pressed - we want to allow navigation around textbox using arrow keys            if (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) {                return;            }            var val = ctrl.value;            val = val.replace(/,/g, "")            ctrl.value = "";            val += '';            x = val.split('.');            x1 = x[0];            x2 = x.length > 1 ? '.' + x[1] : '';            var rgx = /(\d+)(\d{3})/;            while (rgx.test(x1)) {                x1 = x1.replace(rgx, '$1' + ',' + '$2');            }            ctrl.value = x1 + x2;        }//Restrict Characters (Numbers Only)        function CheckNumeric() {            return event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode == 46;        }function submitForm() {  return confirm('Do you really want to submit the form?');}
查看完整描述

2 回答

?
小唯快跑啊

TA貢獻1863條經驗 獲得超2個贊

這應該為您完成工作,您不能在函數中使用重置,因為默認情況下是從 js 使用的


//Total Amount Sum Calculator

var sum = 0;



function f(val){

  sum += val;

  document.getElementById("deposit-total").value = sum;

};


function resets(){


  sum = 0;

  document.getElementById("deposit-total").value = 0;



}


//Automatic Comma

function FormatCurrency(ctrl) {

            //Check if arrow keys are pressed - we want to allow navigation around textbox using arrow keys

            if (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) {

                return;

            }


            var val = ctrl.value;


            val = val.replace(/,/g, "")

            ctrl.value = "";

            val += '';

            x = val.split('.');

            x1 = x[0];

            x2 = x.length > 1 ? '.' + x[1] : '';


            var rgx = /(\d+)(\d{3})/;


            while (rgx.test(x1)) {

                x1 = x1.replace(rgx, '$1' + ',' + '$2');

            }


            ctrl.value = x1 + x2;

        }

//Restrict Characters (Numbers Only)

        function CheckNumeric() {

            return event.keyCode >= 48 && event.keyCode <= 57 || event.keyCode == 46;

        }


function submitForm() {

  return confirm('Do you really want to submit the form?');

}

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

<form>

<input type="number" class="input-char-amo" id="deposit-total" step="10000" min="10000" max="5000000" onkeypress="return CheckNumeric()"  required>

              <button type="reset" id="reset" class="correction" onclick="resets()">reset</button><br>

              <div class="amount-buttons-a">

              <button type="button"  id="1" onclick="f(10000)" class="btn-amount">10000</button>

              <button type="button"  id="2" onclick="f(20000)" class="btn-amount">20000</button>

              <button type="button"  id="3" onclick="f(50000)" class="btn-amount">50000</button>

            </div>

            <div class="amount-buttons-b">

              <button type="button"  id="4" onclick="f(100000)" class="btn-amount">100000</button>

              <button type="button"  id="5" onclick="f(500000)" class="btn-amount">500000</button>

              <button type="button"  id="6" onclick="f(1000000)" class="btn-amount">1000000</button>

            </div>

  

  <p class="check-acc">input here</p>

          <input type="text" class="input-check-acc" id="check-account" required>

  <br>

<button id="dep-submit" value="submit" type="submit" >?? </button>

</form>


查看完整回答
反對 回復 2021-11-25
?
一只名叫tom的貓

TA貢獻1906條經驗 獲得超3個贊

reset是 javascript 的保留關鍵字。如果您想查看所有保留字,請查看該鏈接

只需將 的函數名稱更改reset()為另一個名稱即可。


查看完整回答
反對 回復 2021-11-25
  • 2 回答
  • 0 關注
  • 196 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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