下面验证注册资本不是能为空并只能为数字
我在里面定义了一个变量timer = null
在tip
方法我进来就清除
不过好像清除没用?
如果我先不输入,让他提示,然后我再立马添加些字符,
他还是执行上次的定时器
有什么办法能清除,不管在函数里面外面定义都清除不了
<div class="form-group">
<label class="col-sm-2 control-label"><span>*</span>注册资本(万)</label>
<div class="col-sm-7">
<input type="text" class="form-control" id="registermoney" placeholder="请输入注册资本">
</div>
</div>
<a href="#" class="btnsubmit">提交</a>
var v_registermoney = utils.isStringEmpty(_registermoney.val()),
v_registermoney2 = utils.getNumber(_registermoney.val());
tip: function (text, type, callback) {
var timer = null;
clearTimeout(timer);
if (!text) return false;
var typename = type || '';
$('.softlyTipBox').remove();
$('body').append('<div class="softlyTipBox ' + typename + '"><p>' + text + '</p></div>');
var width = $('.softlyTipBox').find('p').width() + 160;
$('body > .softlyTipBox').css({
'width': width,
'margin-left': - parseInt(width/2)
})
setTimeout(function () {
$('body > .softlyTipBox').addClass('show');
}, 150);
timer = setTimeout(function () {
$('body > .softlyTipBox').css({
'width': 0,
'margin-left': 0
});
setTimeout(function () {
$('body > .softlyTipBox').remove();
}, 300);
if (callback) callback();
}, 3000);
}
$('.btnsubmit').click(function(){
if(!v_registermoney){
tip('请输入企业性质', 'error');
return;
}else if(!v_registermoney2){
tip('请输入数字', 'error');
return;
}else{
}
})
你把 timer 作为参数传进去了。这个是 clear 不掉的。