gpt4 book ai didi

javascript - 如何将文本 "Max Characters"添加到 JavaScript 计数器?

转载 作者:行者123 更新时间:2023-12-02 17:46:46 25 4
gpt4 key购买 nike

我有一个最多可容纳 125 个字符的 JavaScript 计数器。一旦达到 125,计数器就会显示“125”。我怎样才能让它说“最大字符数”?

<script language="JavaScript">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = field.value.length;
}
</script>

<center>
<form name=myform action="#">
<font size="1" face="arial, helvetica, sans-serif">
( You may enter up to 125 characters. )<br>
<textarea name=message wrap=physical cols=28 rows=4
onKeyDown="textCounter(this.form.message,this.form.remLen,125);"
onKeyUp="textCounter(this.form.message,this.form.remLen,125);"
></textarea>
<br>
<input readonly type=text name=remLen size=3 maxlength=3 value="0"> characters total</font>
</form>
</center>

最佳答案

function textCounter (field, countfield, maxlimit) {
if (field.value.length > maxlimit) {
field.value = field.value.substring(0, maxlimit);
countfield.value = 'max characters';
} else { // otherwise, update 'characters left' counter
countfield.value = field.value.length;
}
}

关于javascript - 如何将文本 "Max Characters"添加到 JavaScript 计数器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21691023/

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