Home >Web Front-end >JS Tutorial >JS determines the number of bytes in a string and intercepts the length
var matchWords;
var inputNum = document.getElementById("txtTitle").value.replace(/[^x00-xff]/g, "**").length; // get The number of bytes entered
. putedWord").innerHTML = inputNum + "Word Section," + matchWords + "Character";
document.getElementById("inputtingWord").innerHTML = (200 - inputNum) + "Letter," + (Math.round(((200-inputNum)/2)-0.5 ))+"Chinese characters"; ).value.substring(0, matchWords) ;
//If it exceeds 200 bytes, intercept it to 200 bytes
="txtTitle" type="text" class="inputText" runat ="server" onpropertychange="notifyTextLength();" />
Currently input You can also enter