JavaScript实现谷歌,百度切换搜索功能

 
  
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html xmlns ="http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" />
< title > 无标题文档 </ title >
< style type ="text/css" >
*
{ margin : 0 ; padding : 0 ; }
ul
{ list-style : none }
body
{}
a
{ text-decoration : none ; color : #333 ; }
#search
{ font-size : 12px ; border : 1px solid orange ; width : 600px ; margin : 50px auto ; overflow : hidden }
#nav
{ height : 20px }
#nav li
{ float : left ; padding : 0 10px }
#logo
{ float : left ; width : 64px ; height : 64px ; overflow : hidden }
.search_c
{ width : 500px ; float : right }
.text
{ clear : both }
#text
{ width : 280px ; height : 25px ; color : #ccc }
img
{ border : none ; }
</ style >
< script type ="text/javascript" >
var g;
function text(which){
for ( var i = 0 ; i < which.elements.length; i ++ ){
var inp = which.elements[i];
if (inp.type == " button " ){
continue ;
}
inp.onfocus
= function (){
if ( this .value == this .defaultValue){
this .value = "" ;
this .style.color = " #000 " ;
}
}
inp.onblur
= function (){
if ( this .value == "" || this .value.length <= 0 ){
this .value = this .defaultValue;
this .style.color = " #ccc " ;
}
}
}
}

function biaodan(){
for ( var j = 0 ; j < document.forms.length; j ++ ){
text(document.forms[j])
}
}

function nav(target,g){
var href = target.getAttribute( " href " );
var img = document.getElementById( " img " );
img.setAttribute(
" src " ,href);
if (g == " google " ){
document.getElementById(
" bt " ).onclick = function (){
google();
}
}
else {
document.getElementById(
" bt " ).onclick = function (){
baidu();
}
}
}

function google(){
woman
= document.getElementById( ' text ' ).value;
window.location.href
= " http://www.google.com.hk/search?hl=zh-CN&source=hp&biw=1024&bih=625&q= " + woman + " &btnG=Google+%CB%D1%CB%F7&aq=f&aqi=&aql=&oq= " ;
}

function baidu(){
woman
= document.getElementById( ' text ' ).value;
window.location.href
= " http://www.baidu.com/s?tn=monline_dg&bs=%E8%F3%B5%D9%B8%D4%B6%B9%B8%AF%B8%C9&f=8&wd= " + woman;
}



</ script >
</ head >

< body >

</ body >


< div id ="search" >
< h1 id ="logo" >
< a href ="" >< img src ="images/google.jpeg" id ="img" /></ a >
</ h1 >
< div class ="search_c" >
< div id ="nav" >
< ul >
< li >< a href ="http://images.cnblogs.com/cnblogs_com/blueDream2011/291172/o_google.jpg " onclick ="nav(this,'google');return false" > 谷歌 </ a ></ li >
< li >< a href ="http://images.cnblogs.com/cnblogs_com/blueDream2011/291172/o_baidu.png " onclick ="nav(this,'baidu');return false" > 百度 </ a ></ li >
</ ul >
</ div >
< div class ="text" >
< form action ="" method ="post" >
< input type ="text" id ="text" name ="text" value ="请输入您要搜索的内容!" /> < input type ="button" value ="搜索" id ="bt" />
</ form >

</ div >
</ div >
< script type ="text/javascript" > biaodan(); </ script >
</ div >
</ html >

转载于:https://www.cnblogs.com/blueDream2011/archive/2011/03/31/2001312.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值