The example in this article describes the input prompt special effects code for color changing in js when matching. Share it with everyone for your reference. The details are as follows:
This is a js input prompt effect. When you enter letters in the input box, if there are items in the categories listed below that match your letters, then these contents will turn red and be highlighted. It is basically the same as the input box drop-down prompt, just in a different way.
The screenshot of the running effect is as follows:
The online demo address is as follows:
http://demo.jb51.net/js/2015/js-tips-cha-color-codes/
The specific code is as follows:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>一种输入提示特效,匹配时换色</title> <style type="text/css"> html, body { margin:20px; padding:0; } body { color:#454444; padding: 0; font:12px/30px "宋体"; font-family:Tahoma;} a { color:#454444; text-decoration:none; } a:visited { color:#454444; } a:hover, a:active, a:focus { color:#ff6842; text-decoration:underline; } .fenlei {margin-bottom:30px; width:100%; float:left;} .fenlei li { float:left; width:20%;} .fenlei span,.fenlei span a,.fenlei span a:link,.fenlei span a:active,.fenlei span a:visited { color:#f35d61;} .red{color:red;} </style> <script> function e(a,f){ for(var i=0,j=a.length;i<j;i++){ f.call(a[i],i); } } function s(o){ var a = document.getElementsByTagName("a"), r = new RegExp(o.value,"i"); e(a,function(n){ c = a[n].innerHTML; if(o.value!="" && r.test(c)){ a[n].innerHTML = "<span>" + c.replace(/<[^>]*>/gi,"") + "</span>"; }else{ a[n].innerHTML = c.replace(/<[^>]*>/gi,""); } }) } </script> </head> <body> <form id="form1" name="form1" method="post" action=""> <input type="text" name="textfield" id="textfield" onkeyup="s(this)" /> <input type="submit" name="button" id="button" value="提交" /> </form> <div class="fenlei"> <ul> <li><a href="#" target="_blank">Adidas阿迪达斯</a></li> <li><a href="#" target="_blank">AFU阿芙</a></li> <li><a href="#" target="_blank">Anna Sui安娜苏</a></li> <li><a href="#" target="_blank">AFU阿芙</a></li> <li><a href="#" target="_blank">Anna Sui安娜苏</a></li> </ul> </div> <div class="fenlei"> <ul> <li><a href="#" target="_blank">barbie芭比</a></li> <li><a href="#" target="_blank">Balo贝罗</a></li> <li><a href="#" target="_blank">barbie芭比</a></li> <li><a href="#" target="_blank">barbie芭比</a></li> <li><a href="#" target="_blank">Balo贝罗</a></li> </ul> </div> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.