可切换搜索引擎的导航网页搜索框,可以换百度、谷歌、搜狗不同的搜索方式

可切换搜索引擎的导航网页搜索框,可以换百度、谷歌、搜狗不同的搜索方式

效果图如下:



代码如下:

<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8">
		<style>
			#search ul {
				list-style-type: none;
				display: block;
				width: 100px;
				height: 33px;
				margin: 0;
				padding: 0;
				border: 0px;
				float: left;
			}
			#search li {
				border: 0px;
				margin: 0px;
				padding: 0px;
			}
			#search .selected {
				display: block;
			}
			#search form {
				margin: 0px;
				padding: 0px;
			}
			#search input {
				height: 30px;
				width: 400px;
				margin: 0px;
			}
			#search .button {
				font-size: 17px;
				font-weight: 600;
				color: #002D96;
				height: 30px;
				width: 110px;
				margin-left: 50px;
				background: #e6efc2;
				opacity: 0.8;
				border: #7fb80e 1px solid;
				cursor: pointer;
				-webkit-border-radius: 2px;
				border-radius: 2px;
			}
		</style>
	</head>

	<body>
		<div id="search" align="center">
			<table>
				<tr>
					<td>
						<ul>
							<li style="display:block;"><img src="image/search_mark/1_wangye_baidu.gif" /></li>
							<li style="display:none;"><img src="image/search_mark/1_wangye_google.gif" /></li>
							<li style="display:none;"><img src="image/search_mark/1_wangye_sougou.gif" /></li>
						</ul>
					</td>
					<td id="from_box" style="padding-left:10px;">
						<form id="from_baidu" style="display:block" action="http://www.baidu.com/baidu" target="_blank" method="get">
							<input name="" type="hidden" value="baidu" />
							<input type="text" name="word" />
							<input class="button" type="submit" value="百度一下" onMouseOver="this.style.opacity='1'" onMouseOut="this.style.opacity='0.7'" />
						</form>
						<form id="from_google" style="display:none" action="http://www.google.com/search" target="_blank" method="get">
							<input type="text" name="q" />
							<input class="button" type="submit" value="google搜索" onMouseOver="this.style.opacity='1'" onMouseOut="this.style.opacity='0.7'" />
						</form>
						<form id="from_sougou" style="display:none" action="http://www.sogou.com/web" target="_blank" name="sogou_queryform">
							<input type="text" name="query">
							<input class="button" type="submit" value="sougou搜索" onMouseOver="this.style.opacity='1'" onMouseOut="this.style.opacity='0.7'" />
						</form>
					</td>
				</tr>
			</table>
		</div>
		<script>
			var search = document.getElementById("search");
			var formbox = document.getElementById('from_box');
			var forms = formbox.getElementsByTagName("form");
			var ul =
				search.getElementsByTagName("ul")[0];
			var li =
				ul.getElementsByTagName("li");
			var length =
				li.length;
			li[0].onclick = function() {
				for (var i = 1; i < length; i++) {
					li[i].style.display =
						"block";
				}
			}
			var n = 0; //第一个显示表单的位置
			for (var i = 1; i < length; i++) {
				li[i].onclick = function(a) {
					return function() {
						//交换显示的html内容
						var temp = li[0].innerHTML;
						li[0].innerHTML = this.innerHTML;
						this.innerHTML = temp;
						for (var j = 1; j < length; j++) {
							li[j].style.display =
								"none";
						}
						//交换表单的显示
						//						alert(li[0].innerHTML.substring(37,7));
						//						alert(li[0].innerHTML.indexOf('baidu'));
						hidden_from(); //隐藏表单
						if (li[0].innerHTML.indexOf('baidu') > 0) {
							document.getElementById('from_baidu').style.display = 'block';
						} else if (li[0].innerHTML.indexOf('google') > 0) {
							document.getElementById('from_google').style.display = 'block';
						} else if (li[0].innerHTML.indexOf('sougou') > 0) {
							document.getElementById('from_sougou').style.display = 'block';
						}
						//						alert(this.innerHTML);
						//						forms[n].style.display = "none";
						//						forms[a].style.display = "block";
						//						n = a;
					}
				}(i);
				li[i].onmouseover = function() {
					this.style.border =
						"#7fb80e 1px solid";
					this.style.background =
						"#f2eada";
				}
				li[i].onmouseout =
					function() {
						this.style.border = "0px";
						this.style.background = "inherit";
					}
			}

			//隐藏搜索框表单的函数
			function hidden_from() {
				for (var j = 0; j < forms.length; j++) {
					forms[j].style.display = "none";
				}
			}
		</script>
	</body>

</html>

源码以及图片下载地址:http://download.csdn.net/detail/u014175572/9205821

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值