Home > Web Front-end > JS Tutorial > body text

js implements input prompt special effects code for color change during matching_javascript skills

WBOY
Release: 2016-05-16 15:44:38
Original
1086 people have browsed it

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>

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template