Home  >  Article  >  Web Front-end  >  Automatically check and replace characters in text boxes

Automatically check and replace characters in text boxes

巴扎黑
巴扎黑Original
2017-05-21 11:30:181207browse

<HTML>
<HEAD>
<META http-equiv=&#39;Content-Type&#39; content=&#39;text/html; charset=gb2312&#39;>
<TITLE>自动检查并替换文本框内的字符</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function replaceChars(entry) {
out = "a"; // 要替代的字母
add = "z"; // 替换后的字母
temp = "" + entry;
while (temp.indexOf(out)>-1) {
pos= temp.indexOf(out);
temp = "" + (temp.substring(0, pos) + add + 
temp.substring((pos + out.length), temp.length));
}
document.subform.text.value = temp;
}
// End -->
</script>
</HEAD>
<BODY >
<center>
<form name="subform">
<input type=text name=text size=40 value="abcdabcd"><br>
<input type=button name=action value="Done!" onClick="replaceChars(document.subform.text.value);">
</form>
</center>

</BODY>
</HTML>


The above is the detailed content of Automatically check and replace characters in text boxes. For more information, please follow other related articles on the PHP Chinese website!

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