Home > Web Front-end > JS Tutorial > body text

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

高洛峰
Release: 2016-11-30 16:29:04
Original
1125 people have browsed it

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

Related labels:
js
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template