作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个代码:
$q = mysql_real_escape_string($_GET["q"]);
$result = mysql_query("SELECT * FROM articles WHERE news_title LIKE '%{$q}%'") or die(mysql_error());
$tablecount = 0;
if(mysql_num_rows($result) != 0){
while($staff = mysql_fetch_array($result)){
echo("
{$staff['news_month']}
{$staff['news_day']}
{$staff['news_year']}
» <a href=\"entry/{$staff['id']}\">{$staff['news_title']}</a><br />
");
}
} else {
echo("Error");
}
因此,当我按下“空格键”时,它会转储数据库中的所有内容。我被困在如何不允许按下空格键清空数据,但我又被困住了!
这是我的 JavaScript:
function showResult(str){
if (str.length==0){
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="0px solid #A5ACB2";
}
}
xmlhttp.open("GET","_lib/_php/livesearch.php?q="+str,true);
xmlhttp.send();
}
最佳答案
trim 字符串以删除周围的空格。
function showResult(str) {
str = str.trim();
...
}
关于javascript - 当我按空格键时,它会转储完整数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27790820/
我正在为我的应用程序使用 Tank-Auth。我唯一的问题是激活和重置帐户密码。 用于登录、注册、注销;我对这些代码没有问题; $route['login'] = "/auth/login"; $ro
我是一名优秀的程序员,十分优秀!