function notifyTextLength() {
var inputNum = document.getElementById("txtTitle").value.replace(/[^\x00-\xff]/g, "**").length; //得到輸入的字節(jié)數(shù)
if (inputNum <= 200) {
matchWords = document.getElementById("txtTitle").value.length;
document.getElementById("inputedWord").innerHTML = inputNum + "字節(jié)," + matchWords + "字符";
document.getElementById("inputtingWord").innerHTML = (200 - inputNum) + "字母,"+(Math.round(((200-inputNum)/2)-0.5))+"漢字";
}
if (inputNum > 200) {
document.getElementById("txtTitle").value = document.getElementById("txtTitle").value.substring(0, matchWords);
//如果超過200字節(jié),就截取到200字節(jié)
}
}
<input id="txtTitle" type="text" class="inputText" runat="server" onpropertychange="notifyTextLength();" />
當(dāng)前已經(jīng)輸入<span id="inputedWord" style="color:red"></span> 還可以輸入<span id="inputtingWord" style="color:Red;"></span>
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com