gpt4 book ai didi

javascript - 当到达某个点时计算字符数

转载 作者:行者123 更新时间:2023-12-03 09:41:47 25 4
gpt4 key购买 nike

我有以下代码,运行良好;

var text_max = 459;
var text_used = 0;
var sms_count = 0;
$('#leftstring').html(text_max + '');
$('#usedstring').html(text_used + '');
$('#sms_count').html(sms_count + '');
$(document).on("keyup","#Message", function() {
var text_length = $('#Message').val().length;
var text_remaining = text_max - text_length;
var text_completed = text_used + text_length;
if(text_length <= 152) {
var smscounts =+ parseInt(smscounts)+1;
}
$('#leftstring').html(text_remaining + '');
$('#usedstring').html(text_completed + '');
$('#sms_count').html(smscounts + '');
});

问题出在 sms_count 上,因为我正在尝试的是:我有 459 个字符的限制,所以我想将其除以 3,因此当字符达到 152 时,应计为 1,然后对于下一个 152,应计为 2 code> 然后最后一个 152 应该算到 3

最佳答案

您可能可以使用 Math.ceil() 来查找必须发送的最小消息数。

var per_text = 152

$(document).on("keyup","#Message", function() {
var text_length = $('#Message').val().length;
var text_remaining = text_max - text_length;
var text_completed = text_used + text_length;
var smscounts = Math.ceil(text_length / per_text);

$('#leftstring').html(text_remaining + '');
$('#usedstring').html(text_completed + '');
$('#sms_count').html(smscounts + '');
});

关于javascript - 当到达某个点时计算字符数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31164572/

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