我试图让PHP的Ajax实时搜索框,到目前为止是工作不错,但似乎我现在面临两个问题:PHP Ajax的实时搜索框
- 第一种是当数据显示在屏幕上,如果我将鼠标移动到搜索框外,我希望它消失。
- 第二个与CSS有关,我想把数据结果的位置放在我的搜索框下方,现在是正确的。
这里的代码:
<div class="widget-container widget_search">
<span class="adds"></span>
<form action="" id="searchform" method="POST">
<p>
<input type="text" id="search" placeholder="Chercher" size="30" name="search">
<button type="submit" id="searchsubmit"></button>
</p>
</form><!--/ #searchform-->
<div id="livesearch" style=" width:auto; height:auto; margin:auto; position: absolute;"></div>
</div><!--/ .widget-container-->
JS:
$(document).ready(function(){
$("#search").keyup(function(){
var valor = $("#search").val();
$.ajax({
type: "POST",
url: "/auto/search/",
data: {word:valor},
success: function(res) {
$('#livesearch').html(res);
}
});
});
});
首先,当鼠标移出时,不希望结果消失,当你点击其他任何地方时,结果应该消失,其次,用你的css设置一个小提琴,这样你可以得到更多的帮助。 – slash197