Home >Web Front-end >JS Tutorial >js automatically converts input Chinese commas into English commas

js automatically converts input Chinese commas into English commas

伊谢尔伦
伊谢尔伦Original
2016-11-22 14:48:045105browse

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>


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