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

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

動(dòng)態(tài)設(shè)置輸入組最小值和最大值

動(dòng)態(tài)設(shè)置輸入組最小值和最大值

眼眸繁星 2021-06-15 12:21:01
我正在尋找一種使用加號(hào)和減號(hào)按鈕更新或驗(yàn)證動(dòng)態(tài)輸入組輸入的最小值和最大值的方法。這是我到目前為止所做的:HTML <div class="center">  <div class="input-group">    <span class="input-group-btn">      <button type="button" class="btn btn-danger btn-number" data-type="minus" data-field="numbergroup'+thisgroupid+'id'+buttonid+'max&'+row.max+'"">        <span class="glyphicon glyphicon-minus"></span>      </button>    </span>    <input type="text" name="numbergroup'+thisgroupid+'id'+buttonid+'max&'+row.max+'"" value="0" class="form-control input-number" min="'+row2.min+'"  max="'+row2.max+'">    <span class="input-group-btn">      <button type="button" class="btn btn-success btn-number" data-type="plus" data-field="numbergroup'+thisgroupid+'id'+buttonid+'max&'+row.max+'"">        <span class="glyphicon glyphicon-plus"></span>      </button>    </span>  </div></div>JS $('.btn-number').click(function(e){e.preventDefault();fieldName = $(this).attr('data-field');console.log(fieldName) var grpmax = fieldName.split('&')[1]; console.log(grpmax)type      = $(this).attr('data-type'); console.log(type)var input = $("input[name='"+fieldName+"']");var currentVal = parseInt(input.val());if (!isNaN(currentVal)) {    if(type == 'minus') {        if(currentVal > input.attr('min')) {            input.val(currentVal - 1).change();        }         if(parseInt(input.val()) == input.attr('min')) {            $(this).attr('disabled', true);        }    } else if(type == 'plus') {        if(currentVal < input.attr('max')) {            input.val(currentVal + 1).change();        }        if(parseInt(input.val()) == input.attr('max')) {            $(this).attr('disabled', true);        }    }} else {    input.val(0);}});$('.input-number').focusin(function(){   $(this).data('oldValue', $(this).val());});$('.input-number').change(function() {minValue =  parseInt($(this).attr('min'));maxValue =  parseInt($(this).attr('max'));valueCurrent = parseInt($(this).val());我正在為每個(gè)輸入字段設(shè)置min和max值,但我沒有為將要?jiǎng)?chuàng)建的每個(gè)輸入組設(shè)置min和max值。我需要設(shè)置組最大值或添加驗(yàn)證以檢查組的總值是否小于或等于grpmax
查看完整描述

1 回答

?
莫回?zé)o

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

嘗試


function add(groupId,val) {

  let inp = document.querySelector(`[name=numbergroup_${groupId}]`);

  inp.value= +inp.value + val;

  if(inp.value<+inp.min) inp.value=inp.min;

  if(inp.value>+inp.max) inp.value=inp.max;

}

Min:-2, Max:5

<div class="center">

  <div class="input-group">

    <span class="input-group-btn">

      <button type="button" onclick="add(123,-1)" >

        <span class="glyphicon glyphicon-minus">-</span>

      </button>

    </span>

    <input type="text" name="numbergroup_123" value="0"  min="-2"  max="5">

    <span class="input-group-btn">

      <button type="button" onclick="add(123,1)" >

        <span class="glyphicon glyphicon-plus">+</span>

      </button>

    </span>

  </div>

</div>


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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