[英]else if in javascript
我正在尝试根据用户输入来计算字符串并显示一些消息:
$('#myInput').keyup(function() {
if(this.value.length<=158)
$('#charCount').text('We will deduct 1 credit from your account');
else if(this.value.length>158 || this.value.length<316)
$('#charCount').text('We will deduct 2 credit from your account');
else if(this.value.length>316 || this.value.length<400)
$('#charCount').text('We will deduct 3 credit from your account');
});
问题是最后一个else if
不起作用...我错过了什么吗?
看起来您的意思是&&,而不是||
$('#myInput').keyup(function() {
if(this.value.length<=158)
$('#charCount').text('We will deduct 1 credit from your account');
else if(this.value.length>158 && this.value.length<=316)
$('#charCount').text('We will deduct 2 credit from your account');
else if(this.value.length>316 && this.value.length<400)
$('#charCount').text('We will deduct 3 credit from your account');
});
else if(this.value.length>158 || this.value.length<316) $('#charCount').text('We will deduct 2 credit from your account'); else if(this.value.length>316 || this.value.length<400) $('#charCount').text('We will deduct 3 credit from your account');
世界上每个数字都大于158 或小于316,因此永远不会达到替代条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.