Home >Web Front-end >JS Tutorial >JS determines the number of bytes in a string and intercepts the length

JS determines the number of bytes in a string and intercepts the length

高洛峰
高洛峰Original
2016-11-30 16:29:041134browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn