[英]How to make Live Search including onload search
I have a textarea which has some value, I need to search it at first(onload), then if I change the text written in textarea, I need to search new text (like google), when the textarea is empty, I need to get some message Now I dont't get the result onload, when I try to edit my text I get result, but if i make textarea empty I get my table full 我有一个有价值的textarea,首先需要搜索它(onload),然后如果我更改了textarea中写的文本,我需要搜索新文本(例如google),当textarea为空时,我需要得到一些消息现在我没有得到结果加载,当我尝试编辑文本时得到结果,但是如果我将textarea设为空,我的表就满了
function searchValue() {
$("#search").on("input",function(){
$search = $("#search").val();
if($search.length!=0){
$.get('search.php',{"s":$search},function($data){
$("#results").html($data);
});
}
});
}
<?php
$connection = new mysqli("localhost", "root", "root", 'google');
$connection->query ("SET NAMES 'utf8'");
$query="SELECT * FROM `googleSearchResult` WHERE `info` LIKE '%$_GET[s]%'";
$data=$connection->query($query);
while ($result = $data->fetch_assoc()){
echo "<br><p><a href='".$result['url']."'style='color:#1a0dab !important; font-size:20px'>".$result['title']."</a></p>";
echo "<p style='color:#006621 !important; font-size:17px'>".$result['url']."</p>";
echo "<p style='color:#545454 !important; font-size:16px'>".$result['info']."</p>"."<br>";
}
$connection->close();
?>
<input class="textarea2" id='search' type="text" value="someValue">
<p id='results'></p>
maybe try adding a "keyup" method too 也许也尝试添加“ keyup”方法
$("#search").keyup(function(){
var search=$(this).val();
if(search!==''){
$.get('search.php',{"s":$search},function($data){
$("#results").html($data);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.