在文本框输入要搜索的文字,然后按回车却无效,但鼠标按下就可以.到底怎么回事啊?
<!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>

解决方案 »

  1.   

    onkeydown加错地方了。要加到text框里而不是button里!
    <!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>
      

  2.   


    <!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>
      

  3.   

    <!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(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>再不行你把我杀了 我艹
      

  4.   

    已经解决了.把form标签去掉了.但是什么原因啊?
    在不去掉form标签的情况下,还有什么办法吗
      

  5.   

    <!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(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>
      

  6.   

    就个文本框,要form干啥,一般搜搜都会把参数暴露在url中
      

  7.   

    第一onkeydown加错了地方,应加文本框里.
    第二方法后面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>
      

  8.   

    或者删除你的<form action="" method="post">