Home >Web Front-end >JS Tutorial >js automatically converts input Chinese commas into English commas
When processing form input tags, we often encounter the problem of separators between several tags. English commas are generally used. However, it is troublesome to switch between Chinese and English input when processing Chinese input, so it needs to be input on the client. Switch Chinese commas to English commas through js, which facilitates both background processing and front-end friendly input. The main principle is that js captures the input event of Chinese commas, and then processes the string. If the input is a Chinese comma, convert it is the English comma.
Without further ado, just post the code as follows:
<input type="text" name="tags" onKeyUp="ReplaceDot(this)"> <script type="text/javascript"> function ReplaceDot(obj) { var oldValue=obj.value; while(oldValue.indexOf(",")!=-1)//寻找每一个中文逗号,并替换 { obj.value=oldValue.replace(",",","); oldValue=obj.value; } obj.value = oldValue; } </script>