1 回答
TA贡献1865条经验 获得超7个赞
尝试
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>
添加回答
举报