jQuery。input type=“number”标签,有两个按钮,点击分别是数字加减100,
jQuery。inputtype=“number”标签,有两个按钮,点击分别是数字加减100,当数字为0时,减法的按钮失效怎么做;<%@pagecontentType="...
jQuery。input type=“number”标签,有两个按钮,点击分别是数字加减100,当数字为0时,减法的按钮失效怎么做;
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button{
-webkit-appearance: none !important;
margin: 0;
}
</style>
</head>
<body>
<div class="input-group " style="text-align: center;margin-top:16px;margin-left: -7px;position: relative;background-color:#fff;">
<span class="content-icon-item-1" style="border: 1px solid #999;padding: 14px 9px 11px 12px;text-align: center"><img src="/mobile/images/Symbol-1.png" width="16" height="7"> </span>
<input type="number" id="invest-number" placeholder="请输入投资金额" style="width: 60%; height: 44px;margin-top:-6px;"/>
<span class="content-icon-item-2" style="border: 1px solid #999 ;margin-left:-5px;padding: 14px 12px 11px 14px;"><img src="/mobile/images/symbol-2.png" width="16" height="16"> </span>
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<script>
$(function(){
var num = 0;
var totalnum= 0;
$('.content-icon-item-2').click(function(){
var num = parseInt($('#invest-number').val());
totalnum = num + 100;
$('#invest-number').val(totalnum);
});
$(".content-icon-item-1").click(function(){
var num = parseInt($('#invest-number').val());
totalnum = num - 100;
$('#invest-number').val(totalnum);
})
$('#invest-number').val();
});
</script>
</body>
</html>
现在点击后可以出现负数,我想要调整为,数值为0,减法就失效 展开
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
<style>
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button{
-webkit-appearance: none !important;
margin: 0;
}
</style>
</head>
<body>
<div class="input-group " style="text-align: center;margin-top:16px;margin-left: -7px;position: relative;background-color:#fff;">
<span class="content-icon-item-1" style="border: 1px solid #999;padding: 14px 9px 11px 12px;text-align: center"><img src="/mobile/images/Symbol-1.png" width="16" height="7"> </span>
<input type="number" id="invest-number" placeholder="请输入投资金额" style="width: 60%; height: 44px;margin-top:-6px;"/>
<span class="content-icon-item-2" style="border: 1px solid #999 ;margin-left:-5px;padding: 14px 12px 11px 14px;"><img src="/mobile/images/symbol-2.png" width="16" height="16"> </span>
</div>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<script>
$(function(){
var num = 0;
var totalnum= 0;
$('.content-icon-item-2').click(function(){
var num = parseInt($('#invest-number').val());
totalnum = num + 100;
$('#invest-number').val(totalnum);
});
$(".content-icon-item-1").click(function(){
var num = parseInt($('#invest-number').val());
totalnum = num - 100;
$('#invest-number').val(totalnum);
})
$('#invest-number').val();
});
</script>
</body>
</html>
现在点击后可以出现负数,我想要调整为,数值为0,减法就失效 展开
1个回答
展开全部
简单点的做法如下:
$(".content-icon-item-1").click(function(){
var num = parseInt($('#invest-number').val());
totalnum = num - 100;
if(totalnum < 0){
$('#invest-number').val("0");
return;
}
$('#invest-number').val(totalnum);
})
复杂点的做法如下:
function minusMoney(){
var num = parseInt($('#invest-number').val());
totalnum = num - 100;
if(totalnum < 0){
$('#invest-number').val("0");
$(".content-icon-item-1").off("click");
return;
}
$('#invest-number').val(totalnum);
}
$(".content-icon-item-1").click(minusMoney);
$('.content-icon-item-2').click(function(){
var num = parseInt($('#invest-number').val());
totalnum = num + 100;
if(num <= 0 && totalnum > 0){
$(".content-icon-item-1").on("click", minusMoney);
}
$('#invest-number').val(totalnum);
});
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询