php:检查键盘上的按下按钮

时间:2013-10-30 10:20:41

标签: javascript jquery

我的页面中有以下结构:

page.php

<html>
    <head>
        <title>Page title</title>
        <script src="jquery-2.0.3.js"></script>
        <script type="text/javascript">
            function search(value){
                window.location.href="page.php?search=" + value;
            }
        </script>
    </head>
    <body>
        <?php
            if(!empty($_GET['search'])){
                //SQL-statement with WHERE column LIKE $_GET['search']
            } else {
                //Other SQL-statement without WHERE column LIKE $_GET['search']
            }
        ?>
        <h1>Title</h1>
        <input type="text" onKeyUp="search(this.value);" 
               value="<?php echo $_GET['search']; ?>">
    </body>
</html>

正如您所读到的,重要的是,当按下spacebar时,它会在_$_GET['search']字段中放置input,它是{ {1}}

3 个答案:

答案 0 :(得分:0)

也许尝试这样的替换:

var new_string = old_str.replace("&nbsp;", "_");

答案 1 :(得分:0)

value' '(单个空格)和 window.location.href="page.php?search=" + value; 将进行URL编码,因此空格将变为&nbsp;(URL实体)

您必须urldecode($_GET['search']);将其变回空格字符。 (http://us2.php.net/urldecode

答案 2 :(得分:0)

试试这个,

<?php
    if(isset($_GET['search']) && !empty($_GET['search'])){
         $q=urldecode($_GET['search']);// use it in your query
         //SQL-statement with WHERE column LIKE $_GET['search']
    } else {
        //Other SQL-statement without WHERE column LIKE $_GET['search']
    }
?>

阅读urldecode()