当用户输入时,我的文本区域可以计算字符串/字符。这是我的jsfiddle .
我的问题是,当字符串/字符为 158 以上时,我想设置条件平均值,我想在 <div id="message">We will deduct 2 credit from your account</div>
内显示消息同样,当字符串/字符为 316 时,消息将更新并显示< div id="message">We will deduct 3 credit from your account</div>
并继续..
示例:
158 *2
158 = We will deduct 2 credit from your account
316 = We will deduct 3 credit from your account
474 = We will deduct 4 credit from your account
632 = We will deduct 5 credit from your account
...
最佳答案
尝试一下
$('#myInput').keyup(function() {
$('#charCount').text(this.value.length);
var c = parseInt(this.value.length / 158);
if(c > 0)
$('#message').text('We will deduct '+c+' credit from your account');
});
关于javascript - 使用带条件的 jQuery 计算字符串数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13134765/