代码改变世界

js做搜索框

2013-02-24 00:15  youxin  阅读(649)  评论(0编辑  收藏  举报
<html>
<head>
<script language="javascript" >
function baidu()
{
  var startDate, endDate ,d ;
  d = new Date();
  startDate =d.getYear() + "-"+ (d.getMonth() + 1) + "-" + d.getDate() ;      //开始日期
  endDate =d.getYear() + "-"+ d.getMonth()  + "-" + d.getDate();         // 结束日期
window.open("http://www.baidu.com/s?tn=tcha_pg&word="+startDate+"endDate="+endDate+"");
}
function google()
{
window.open("http://www.google.cn/search?hl=zh-CN&q="+document.myform.mytext.value+"
&btnG=Google+%E6%90%9C%E7%B4%A2&meta=&aq=-1&oq=");  
}
function KeyDown(event)  //回车提交数据  ( 这样火符也可以用 )
{
event = event ? event : (window.event ? window.event : null);
if (event.keyCode == 13)
{
event.returnValue=false;
event.cancel = true;
google();
}
}
</script>
</head>
<body>
<center>
<form name="myform">

<input type="text" value="请输入搜索内容" name="mytext" maxlength="2048" size="55"

onkeydown="KeyDown(event)" onMouseOver="this.select();"/>

<input type="button"  value="google"  onclick="google()" /> 
<input type="button" value="最新报告" onclick="baidu()" />
</form>
</center>
</body>
</html>