在文本框输入要搜索的文字,然后按回车却无效,但鼠标按下就可以.到底怎么回事啊?
<!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">
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){
var href = target.getAttribute("href");
var img = document.getElementById("img");
img.setAttribute("src",href);
} function bt(){
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 jianpan(){
if(event.keyCode==13){
bt();
}
}
</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="images/google.jpeg" onclick="nav(this);return false">谷歌</a></li>
<li><a href="images/baidu.png" onclick="nav(this);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="搜索" onclick="bt()" onkeydown="jianpan()">
</form>
</div>
</div>
<script type="text/javascript">biaodan();</script>
</div>
</html>
<!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">
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){
var href = target.getAttribute("href");
var img = document.getElementById("img");
img.setAttribute("src",href);
} function bt(){
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 jianpan(){
if(event.keyCode==13){
bt();
}
}
</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="images/google.jpeg" onclick="nav(this);return false">谷歌</a></li>
<li><a href="images/baidu.png" onclick="nav(this);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="搜索" onclick="bt()" onkeydown="jianpan()">
</form>
</div>
</div>
<script type="text/javascript">biaodan();</script>
</div>
</html>
<!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:#000}
img{border:none;}
</style>
<script type="text/javascript">
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){
var href = target.getAttribute("href");
var img = document.getElementById("img");
img.setAttribute("src",href);
} function bt(){
var 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 jianpan(e){
var eve=e || window.event;
if(eve.keyCode==13){
// alert(3);
bt();
}
}
</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="images/google.jpeg" onclick="nav(this);return false">谷歌</a></li>
<li><a href="images/baidu.png" onclick="nav(this);return false">百度</a></li>
</ul>
</div>
<div class="text">
<input type="text" id="text" name="text1" value="请输入您要搜索的内容!" onkeydown="jianpan(event)"> <input type="button" value="搜索" onclick="bt()">
</div>
</div>
<script type="text/javascript">biaodan();</script>
</div>
</html>
<!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">
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){
var href = target.getAttribute("href");
var img = document.getElementById("img");
img.setAttribute("src",href);
} function bt(){
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 jianpan(){
if(event.keyCode==13){
bt();
}
}
</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="images/google.jpeg" onclick="nav(this);return false">谷歌</a></li>
<li><a href="images/baidu.png" onclick="nav(this);return false">百度</a></li>
</ul>
</div>
<div class="text">
<input type="text" id="text" name="text" value="请输入您要搜索的内容!" onkeydown="jianpan()" /> <input type="button" value="搜索" onclick="bt()">
</div>
</div>
<script type="text/javascript">biaodan();</script>
</div>
</html>
<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">
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){
var href = target.getAttribute("href");
var img = document.getElementById("img");
img.setAttribute("src",href);
} function bt(){
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 jianpan(event){
if(event.keyCode==13){
bt();
}
}
</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="images/google.jpeg" onclick="nav(this);return false">谷歌</a></li>
<li><a href="images/baidu.png" onclick="nav(this);return false">百度</a></li>
</ul>
</div>
<div class="text">
<input type="text" id="text" name="text" value="请输入您要搜索的内容!" onkeydown="jianpan(event)" /> <input type="button" value="搜索" onclick="bt()">
</div>
</div>
<script type="text/javascript">biaodan();</script>
</div>
</html>再不行你把我杀了 我艹
在不去掉form标签的情况下,还有什么办法吗
<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">
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){
var href = target.getAttribute("href");
var img = document.getElementById("img");
img.setAttribute("src",href);
} function bt(){
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 jianpan(event){
var e = event || window.event;//兼容firefox
if(e.keyCode==13){
bt();
}
}
</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="images/google.jpeg" onclick="nav(this);return false">谷歌</a></li>
<li><a href="images/baidu.png" onclick="nav(this);return false">百度</a></li>
</ul>
</div>
<div class="text">
<input type="text" id="text" name="text" value="请输入您要搜索的内容!" onkeydown="jianpan(event)" /> <input type="button" value="搜索" onclick="bt()">
</div>
</div>
<script type="text/javascript">biaodan();</script>
</div>
</html>
第二方法后面return false;
<!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"> 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) {
var href = target.getAttribute("href");
var img = document.getElementById("img"); img.setAttribute("src", href);
} function bt() {
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=";
return false;
}
function jianpan() {
if (event.keyCode == 13) {
return bt();
}
}
</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="images/google.jpeg" onclick="nav(this);return false">谷歌</a></li>
<li><a href="images/baidu.png" onclick="nav(this);return false">百度</a></li>
</ul>
</div>
<div class="text">
<form action="" method="post">
<input type="text" id="text" name="text" value="请输入您要搜索的内容!" onkeydown="return jianpan()"/>
<input type="button" value="搜索" onclick="bt()">
</form>
</div>
</div> <script type="text/javascript"> biaodan();</script></div>
</html>