我的页面中有以下结构:
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}}
答案 0 :(得分:0)
也许尝试这样的替换:
var new_string = old_str.replace(" ", "_");
答案 1 :(得分:0)
value
是' '
(单个空格)和
window.location.href="page.php?search=" + value;
将进行URL编码,因此空格将变为
(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']
}
?>