您能看一下这个演示吗?让我知道如何在使用Bootstrap TouchSpin library时为大于0的数字添加+,或者从小于0的数字中移除-符号
$("input[name='demo1']").TouchSpin({
min: -6,
max: 6,
step: 0.25,
decimals: 2,
boostat: 5,
maxboostedstep: 10
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>
<input id="demo1" type="text" value="0" name="demo1">
发布于 2018-08-18 10:38:55
您可以为input的change事件添加一个事件侦听器,并在输入的值上添加一个加号(+),如果它是肯定的,因为更改事件是由插件在原始输入上触发的,并且可以被侦听。
$("input[name='demo1']").TouchSpin({
min: -6,
max: 6,
step: 0.25,
decimals: 2,
boostat: 5,
maxboostedstep: 10
}).change(function(){
var val = $(this).val();
if(parseFloat(val)>0){
$(this).val("+"+val);//add + for positive numbers
}
});<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-touchspin/4.2.5/jquery.bootstrap-touchspin.min.js"></script>
<input id="demo1" type="text" value="0" name="demo1">
https://stackoverflow.com/questions/51904690
复制相似问题