gpt4 book ai didi

javascript - 如果字符数 =< 160,如何将初始 SMS 数显示为 1?

转载 作者:可可西里 更新时间:2023-11-01 13:22:02 24 4
gpt4 key购买 nike

我有一个 jquery 代码,我想显示当前正在键入的字符数、剩余字符数以及 SMS 等的数量。 0 到 160 之间的值是 1 条 SMS,高于该值且小于 321 的任何值都是拖曳 SMS。高于 160 的值向文档打印 2 条短信,但初始值永远不会更改为 1。它始终为零。我该如何做对?这是 jquery 代码:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

var text_max = 481;

$('#textarea_feedback').html(text_max + ' characters remaining');

$('#textarea1').keyup(function() {

var text_length = $('#textarea1').val().length;

var cur = text_length;

var text_remaining = text_max - text_length;


$('#textarea_feedback').html(text_remaining + ' characters remaining');

$('#textarea_cur').html(cur + ' current characters');

var sms = 1;

$('#smsNum').html(sms + ' SMS');

if(cur <= 160) {

$('#smsNum').html(sms);

}if(cur >= 161) {

$('#smsNum').html(sms += 1 );

}else{

$('#smsNum').html(sms -= 1 );
}

});

});

</script>

The HTML code:

<span id="textarea_cur"></span>

<div id="smsNum"> SMS </div>

<textarea id="textarea1" rows="5" cols="40" maxlength="482" >

</textarea>

<span id="textarea_feedback">

</span>

最佳答案

if(cur >= 161) {
$('#smsNum').html(短信+= 1);
}

这只会给你 2 条短信,无论你在 160 之后增加多少字符数,因为你没有计算短信数量,只是让你的 sms = cur/160

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

var text_max = 481;

$('#textarea_feedback').html(text_max + ' characters remaining');

$('#textarea1').keyup(function() {

var text_length = $('#textarea1').val().length;

var cur = text_length;

var text_remaining = text_max - text_length;


$('#textarea_feedback').html(text_remaining + ' characters remaining');

$('#textarea_cur').html(cur + ' current characters');

var sms = parseInt(cur/160);

$('#smsNum').html(sms + ' SMS');


});

});

</script>

The HTML code:

<span id="textarea_cur"></span>

<div id="smsNum"> SMS </div>

<textarea id="textarea1" rows="5" cols="40" maxlength="482" >

</textarea>

<span id="textarea_feedback">

</span>

关于javascript - 如果字符数 =< 160,如何将初始 SMS 数显示为 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45504866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com