我尝试对许多输入字段进行 jQuery 实时搜索。
只有 1 个输入字段(没有数组),它工作得很好,
但是有许多带有数组的搜索字段,什么都没有发生。
(livesearch.php文件现在只说“echo 'test';”)
我希望你能帮助我。
感谢您的回答。
但它仍然不起作用。
我只是不明白为什么 ajax 部分不起作用。
我将代码编辑为以下内容:
<html><head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<div id="main">
First search field:<br>
<input type="text" name="search[]" class="search" autocomplete="off">
<div></div>
Second search field:<br>
<input type="text" name="search[]" class="search" autocomplete="off">
<div></div>
</div>
<script>
$(document).ready(function() {
$('.search').on("keyup", function(e) {
var search_string = $(this).val();
// Do Search
if (search_string == '') {
$(this).next().fadeOut();
}else{
$(this).next().fadeIn();
//$(this).next().html("hallo"); //THIS WORKS!!!
$.ajax({
type: "POST",
url: "./livesearch.php",
data: { query: search_string },
cache: false,
success: function(data){
$(this).next().html(data); //THIS DOESN'T WORK!!!
}
});
};
});
});
</script>
</body>
</html>