本文及代码由 renx 原创,版权所有,随便使用,哪位大大看得起在下,有用到的话,我很荣幸您能告诉我.
开始
为了做这个yahoo搜索框,我分了三步:
1. 先做搜索分类的按钮,点击后会和其他按钮看上去比较不一样,这个是挺简单的
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>search_bar</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<style>
body,html{
font-size:12px;
}
.none{display:none;}
.block{display:block;}
.s_c{width:800px;text-align:center;}
.s_cul{clear:both;margin:0;}
.s_cli{list-style:none;float:left;position:relative;width:70px;}
.c_0{padding:0px10px0px10px;line-height:22px}
.c_0a{color:#666;text-decoration:none;}
.c_1{padding:4px0;width:70px;
background:#0075eb;border:1pxsolid#054576;border-bottom-width:0;text-decoration:none;}
.c_1a{color:#FFF;font-weight:bold;text-decoration:none;}
.c_2{padding:4px0;width:70px;background:#a10303;border:1pxsolid#662626;border-bottom-width:0;}
position:absolute;bottom:-7px;left:0;}
.c_3{padding:4px0;width:70px;background:#B01FAA;border:1pxsolid#760473;border-bottom-width:0;}
.whitea{color:#FFF;font-weight:bold;text-decoration:none;}
</style>
<scriptlanguage="javascript">
functionaa(s_id){
for(i=1;i<4;i++){
if(i==s_id){
document.getElementById("m"+i).className="c_"+i+"white";
}
else{
document.getElementById("m"+i).className="c_0";
}
}
}
</script>
</head>
<body>
<divclass="s_c"><ul>
<li><divid="m1"class="c_1"><ahref="###"onClick="aa(’1’)">分类第一</a></div></li>
<li><divid="m2"class="c_0"><ahref="###"onClick="aa(’2’)">分类第二</a></div></li>
<li><divid="m3"class="c_0"><ahref="###"onClick="aa(’3’)">分类第三</a></div></li>
</ul>
</div>
</body>
</html>
当然这还不够,接下来实现第二步效果.
2.加个搜索输入框,而且要能换颜色的
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>search_bar</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<style>
body,html{
font-size:12px;
}
.none{display:none;}
.block{display:block;}
.s_c{width:800px;text-align:center;}
.s_cul{clear:both;margin:0;}
.s_cli{list-style:none;float:left;position:relative;width:70px;}
.s_b{border:1pxsolid#666;}
.s_bspan{padding:20px20px;vertical-align:middle;}
.s_binput{margin:8px8px;}
.search_0{background:#fff;}
.search_1{background:#d2e4fc;}
.search_2{background:#fcd2d2;}
.search_3{background:#F9D3FA;}
.search_4{background:#defbfb;}
.search_5{background:#fce8d2;}
.search_6{background:#FCEBB9;}
.c_0{padding:0px10px0px10px;line-height:22px}
.c_0a{color:#666;text-decoration:none;}
.c_1{padding:4px0;width:70px;
background:#0075eb;border:1pxsolid#054576;border-bottom-width:0;text-decoration:none;}
.c_1a{color:#FFF;font-weight:bold;text-decoration:none;}
.c_2{padding:4px0;width:70px;background:#a10303;border:1pxsolid#662626;border-bottom-width:0;}
position:absolute;bottom:-7px;left:0;}
.c_3{padding:4px0;width:70px;background:#B01FAA;border:1pxsolid#760473;border-bottom-width:0;}
.whitea{color:#FFF;font-weight:bold;text-decoration:none;}
</style>
<scriptlanguage="javascript">
functionaa(s_id){
for(i=1;i<4;i++){
if(i==s_id){
document.getElementById("s"+i).className="blockbe";
document.getElementById("m"+i).className="c_"+i+"white";
document.getElementById("uid_"+i).focus();
}
else{
document.getElementById("s"+i).className="none";
document.getElementById("m"+i).className="c_0";
}
}
}
</script>
</head>
<body>
<divclass="s_c"><ul>
<li><divid="m1"class="c_1"><ahref="###"onClick="aa(’1’)">分类第一</a></div></li>
<li><divid="m2"class="c_0"><ahref="###"onClick="aa(’2’)">分类第二</a></div></li>
<li><divid="m3"class="c_0"><ahref="###"onClick="aa(’3’)">分类第三</a></div></li>
</ul>
</div>
<divclass="s_b">
<divclass="block"id="s1"><divclass="search_1"><span>SearchtheWeb:</span><inputname="uid"id="uid_1"/><span>按钮</span></div></div>
<divclass="none"id="s2"><divclass="search_2"><span>SearchtheWeb:</span><inputname="uid"id="uid_2"/><span>按钮</span></div></div>
<divclass="none"id="s3"><divclass="search_3"><span>SearchtheWeb:</span><inputname="uid"id="uid_3"/><span>按钮</span></div></div>
</div>
</body>
</html>
3. 现在加个箭头,做个外框,当然也要不同颜色的
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<head>
<title>search_bar</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<style>
body,html{
font-size:12px;
}
.none{display:none;}
.block{display:block;}
.s_c{width:800px;text-align:center;}
.s_cul{clear:both;margin:0;}
.s_cli{list-style:none;float:left;position:relative;width:70px;}
.s_b{border:1pxsolid#666;}
.s_bspan{padding:20px20px;vertical-align:middle;}
.s_binput{margin:8px8px;}
.search_0{background:#fff;}
.search_1{background:#d2e4fc;}
.search_2{background:#fcd2d2;}
.search_3{background:#F9D3FA;}
.search_4{background:#defbfb;}
.search_5{background:#fce8d2;}
.search_6{background:#FCEBB9;}
.c_0{padding:0px10px0px10px;line-height:22px}
.c_0a{color:#666;text-decoration:none;}
.c_1{padding:4px0;width:70px;
background:#0075eb;border:1pxsolid#054576;border-bottom-width:0;text-decoration:none;}
.c_1a{color:#FFF;font-weight:bold;text-decoration:none;}
.c_1b{width:100%;height:11px;background:url("picture/sc1.gif")no-repeat50%bottom;position:absolute;bottom:-7px;left:0;}
.c_2{padding:4px0;width:70px;background:#a10303;border:1pxsolid#662626;border-bottom-width:0;}
.c_2b{width:100%;height:11px;background:url("picture/sc2.gif")no-repeat50%bottom;
position:absolute;bottom:-7px;left:0;}
.c_3{padding:4px0;width:70px;background:#B01FAA;border:1pxsolid#760473;border-bottom-width:0;}
.c_3b{width:100%;height:11px;background:url("picture/sc3.gif")no-repeat50%bottom;position:absolute;bottom:-7px;left:0;}
.c_4{padding:4px0;width:70px;background:#41abb5;border:1pxsolid#297a80;border-bottom-width:0;}
.c_4b{width:100%;height:11px;background:url("picture/sc4.gif")no-repeat50%bottom;position:absolute;bottom:-7px;left:0;}
.c_5{padding:4px0;width:70px;background:#d95000;border:1pxsolid#96450c;border-bottom-width:0;}
.c_5b{width:100%;height:11px;background:url("picture/sc5.gif")no-repeat50%bottom;position:absolute;bottom:-7px;left:0;}
.c_6{padding:4px0;width:70px;background:#ec9e2e;border:1pxsolid#B28B12;border-bottom-width:0;}
.c_6b{width:100%;height:11px;background:url("picture/sc6.gif")no-repeat50%bottom;position:absolute;bottom:-7px;left:0;}
.whitea{color:#FFF;font-weight:bold;text-decoration:none;}
</style>
<scriptlanguage="javascript">
functionaa(s_id){
for(i=1;i<7;i++){
if(i==s_id){
document.getElementById("s"+i).className="blockbe";
document.getElementById("m"+i).className="c_"+i+"white";
document.getElementById("uid_"+i).focus();
}
else{
document.getElementById("s"+i).className="none";
document.getElementById("m"+i).className="c_0";
}
}
}
</script>
</head>
<body>
<divclass="s_c"><ul>
<li><divid="m1"class="c_1"><ahref="###"onClick="aa(’1’)"><b></b>分类第一</a></div></li>
<li><divid="m2"class="c_0"><ahref="###"onClick="aa(’2’)"><b></b>分类第二</a></div></li>
<li><divid="m3"class="c_0"><ahref="###"onClick="aa(’3’)"><b></b>分类第三</a></div></li>
<li><divid="m4"class="c_0"><ahref="###"onClick="aa(’4’)"><b></b>分类第四</a></div></li>
<li><divid="m5"class="c_0"><ahref="###"onClick="aa(’5’)"><b></b>分类第五</a></div></li>
<li><divid="m6"class="c_0"><ahref="###"onClick="aa(’6’)"><b></b>分类第六</a></div></li>
</ul>
</div>
<divclass="s_b">
<divclass="block"id="s1"><divclass="search_1"><span>SearchtheWeb:</span><inputname="uid"id="uid_1"/><span>按钮</span></div></div>
<divclass="none"id="s2"><divclass="search_2"><span>SearchtheImages:</span><inputname="uid"id="uid_2"/><span>按钮</span></div></div>
<divclass="none"id="s3"><divclass="search_3"><span>SearchtheImages:</span><inputname="uid"id="uid_3"/><span>按钮</span></div></div>
<divclass="none"id="s4"><divclass="search_4"><span>SearchtheAudio</span><inputname="uid"id="uid_4"/><span>按钮</span></div></div>
<divclass="none"id="s5"><divclass="search_5"><span>SearchtheNews</span><inputname="uid"id="uid_5"/><span>按钮</span></div></div>
<divclass="none"id="s6"><divclass="search_6"><span>SearchtheShopping</span><inputname="uid"id="uid_6"/><span>按钮</span></div></div>
</div>
</body>
</html>
现在看来差不多可以了,就是效率有点低,下次再优化一下