搜索回车跳转页面

如图搜索框,想要实现文本输入内容后敲击回车(等同于点击后面的小放大镜图标)后跳转到搜索结果的页面

<div class="head-ss02">
       <input name="ss" type="text" id="search" onkeypress="javascript:enterSubmitss(this,event);" size="2" />
       <input type="text" id="sname" style="display: none" />
</div>
<div class="head-ss01">
      <a href="javascript:OnSubmit('search')">
      <img src="images/ss.png" border="0" />
    </a> </div>

js代码如下:

<script type="text/javascript">
        function OnSubmit(tags) {
            var tag = document.getElementById(tags);
            if (tag.value == "") {
                window.location.href = "Searchkeyword.aspx?key=" + tag.value;
            }
            if (tag.length > 20) {
                alert("您输入的字符太长,小于20个字符");
                return false;
            }
            window.location.href = "Searchkeyword.aspx?key=" + tag.value;
        }
        function enterSubmitss(src, e) {
            if (window.event)
                keyPressed = window.event.keyCode; // IE
            else
                keyPressed = e.which; // Firefox
            if (keyPressed == 13) {
                submitFormss();

            }
        }
        function submitFormss() {
            var tag = document.getElementById("search");
           
            if (tag.value == "") {
                window.location.href = "Searchkeyword.aspx?key=" + tag.value;
            }
            if (tag.length > 20) {
                alert("您输入的字符太长,小于20个字符");
                return false;
            }
          
            location.href = "Searchkeyword.aspx?key=" + tag.value;
            
        }
</script>

 

posted @ 2014-05-27 16:32  后知然后觉  阅读(794)  评论(0编辑  收藏  举报