Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何按;输入“;要重定向到其他页面?_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 如何按;输入“;要重定向到其他页面?

Javascript 如何按;输入“;要重定向到其他页面?,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我正在研究搜索功能,我做得很好,以得到我想要的结果。我有一个搜索文本字段,允许用户输入值,JavaScript将帮助我获取文本字段值的相关数据。现在我想我的文本字段可以是功能,当我按下它使用按钮“进入”。一旦我按下“回车”按钮,它会将我重定向到一个新页面,该页面在文本字段中显示我输入的关键字的所有相关数据 这是我在HTML页面中的JavaScript和HTML代码: <script> $(document).ready(function() { // Icon Clic

我正在研究搜索功能,我做得很好,以得到我想要的结果。我有一个搜索文本字段,允许用户输入值,JavaScript将帮助我获取文本字段值的相关数据。现在我想我的文本字段可以是功能,当我按下它使用按钮“进入”。一旦我按下“回车”按钮,它会将我重定向到一个新页面,该页面在文本字段中显示我输入的关键字的所有相关数据

这是我在HTML页面中的JavaScript和HTML代码:

<script>
$(document).ready(function() {  

    // Icon Click Focus
    $('div.icon').click(function(){
        $('input#search').focus();
    });

    // Live Search
    // On Search Submit and Get Results
    function search() {
        var query_value = $('input#search').val();
        $('b#search-string').html(query_value);
        if(query_value !== ''){
            $.ajax({
                type: "POST",
                url: "search.php",
                data: { query: query_value },
                cache: false,
                success: function(html){
                    $("ul#results").html(html);
                }
            });
        }return false;    
    }

    $("input#search").live("keyup", function(e) {
        // Set Timeout
        clearTimeout($.data(this, 'timer'));

        // Set Search String
        var search_string = $(this).val();

        // Do Search
        if (search_string == '') {
            $("ul#results").fadeOut();
            $('h4#results-text').fadeOut();
        }else{
            $("ul#results").fadeIn();
            $('h4#results-text').fadeIn();
            $(this).data('timer', setTimeout(search, 0));
        };
    });

});
</script>

SEARCH<input type="text" id="search" autocomplete="off">
                    <ul id="results" style="display:none"></ul>

$(文档).ready(函数(){
//图标单击焦点
$('div.icon')。单击(函数(){
$('input#search').focus();
});
//实时搜索
//搜索时提交并获取结果
函数搜索(){
var query_value=$('input#search').val();
$('b#搜索字符串').html(查询值);
如果(查询值!=''){
$.ajax({
类型:“POST”,
url:“search.php”,
数据:{query:query\u value},
cache:false,
成功:函数(html){
$(“ul#results”).html(html);
}
});
}返回false;
}
$(“输入搜索”).live(“键控”,功能(e){
//设置超时
clearTimeout($.data(此为“计时器”);
//设置搜索字符串
var search_string=$(this.val();
//搜索
如果(搜索字符串==''){
$(“ul#results”).fadeOut();
$('h4#结果文本').fadeOut();
}否则{
$(“ul#results”).fadeIn();
$('h4#结果文本').fadeIn();
$(this).data('timer',setTimeout(search,0));
};
});
});
搜寻

    在文本中输入值后,JavaScript将调用search.php以获取所有相关数据。但我不能单击文本字段来显示所有值。希望你们能给我一个解决方案。感谢使用advanced。

    请尝试使用jQuery 1.8或最低版本

    $("input#search").live("keyup", function(e)
            if(e.which == 13) {
                //perform your operations
            }
        });
    

    您可以将其制作为表单,以便在用户点击enter时提交

    <form method="get" action="search page.php" onsubmit="return validate();">
        SEARCH<input type="text" id="search" autocomplete="off">
        <ul id="results" style="display:none"></ul>
    </form>
    
    <script type="text/JavaScript">
    function validate() {
        //If the form value is "" (nothing)
        if (document.getElementById("search").value == "") {
            return false; //Stop the form from submitting
        }
        return true;
    }
    </script>
    
    
    搜寻
    
      函数验证(){ //如果表单值为“”(无) if(document.getElementById(“搜索”).value==“”){ return false;//停止表单提交 } 返回true; }
      我无法理解您的问题。你想做一个类似谷歌搜索的表单吗?我有一个文本字段来填充值,我想要的是当我点击“回车”按钮时,文本字段可以提交到其他页面。希望这能让您更清楚。“live()”已被弃用,请使用“on()”而不是您使用的jQuery的哪个版本?听起来似乎您只需要一个常规的
      表单
      元素来提交您的查询。如何在字段中没有值时使其不可单击?我对其进行了更新,以便表单中没有任何内容时不会发送。