gpt4 book ai didi

html 中 SMS TextArea 的 Javascript 字符计数器

转载 作者:行者123 更新时间:2023-12-03 01:48:55 24 4
gpt4 key购买 nike

我设计了短信发送页面来发送短信。我使用 Javascript 显示从 160 开始倒数的字符计数。问题是我不知道如何计算每 160 个字符后的短信数量。

我的js函数代码:

function CountCharIndividual(txtIndividualMessage) {
var count = document.getElementById(txtIndividualMessage).value.length;
if (count > 1 && count <= 160) {
document.getElementById('charstatus2').innerHTML = 160 - document.getElementById(txtIndividualMessage).value.length;
}
if (document.getElementById(txtIndividualMessage).value.length > 160 - 1) {
document.getElementById('charstatus2').innerHTML = "Maximum characters reached & now " + "showing new count: " + document.getElementById(txtIndividualMessage).value.length;
}
if (document.getElementById(txtIndividualMessage).value.length >= 160) {
document.getElementById('smsCount').innerHTML = 1;
}
}

它显示了 smsCount 的 innerHTML 中的前 160 个字符,但随后不再增加。

最佳答案

尝试下面的代码,如果有帮助

function CountCharIndividual(txtIndividualMessage) {

var count = document.getElementById(txtIndividualMessage).value.length;
var maxLength = 160;
var smsCount = parseInt(count / maxLength);
if (smsCount > 0) {
document.getElementById('smsCount').innerHTML = smsCount;
} else {
if (count > (maxLength - 1)) {
document.getElementById('charstatus2').innerHTML = "Maximum characters reached & now " + "showing new count: " + count;
} else {
document.getElementById('charstatus2').innerHTML = maxLength - count;
}

}

}

关于html 中 SMS TextArea 的 Javascript 字符计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50507709/

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