Instance of the input box in html automatically jumping to the last character after modification
<input class="m-form-control" onpaste="return false" placeholder="直播间名称" name="name" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5|\u0000-\u00ff|\u3002|\uFF1F| \uFF01|\uff0c|\u3001|\uff1b|\uff1a|\u3008-\u300f|\u2018|\u2019|\u201c|\u201d|\uff08|\uff09|\u2014|\u2026|\u2013|\uff0e]/g,'')" onafterpaste="this.value=this.value.replace(/[^\u4e00-\u9fa5|\u0000-\u00ff|\u3002|\uFF1F|\uFF01|\uff0c|\u3001| \uff1b|\uff1a|\u3008-\u300f|\u2018|\u2019|\u201c| \u201d|\uff08|\uff09|\u2014|\u2026|\u2013|\uff0e]/g,'')">
There are three events, one onpaste is used to prohibit pasting, and the remaining two are used to remove special characters. The reason is replace, replace will be like re-typing, so the cursor will be resolved at the end
, and the replace event will be triggered when the cursor is lost
The above is the detailed content of Example of automatically jumping to the last character after the input box in HTML is modified. For more information, please follow other related articles on the PHP Chinese website!