Javascript 组合JS函数鼠标
我想合并JS函数,但这不起作用。有人对我的代码有什么建议吗Javascript 组合JS函数鼠标,javascript,jquery,Javascript,Jquery,我想合并JS函数,但这不起作用。有人对我的代码有什么建议吗 $(document).ready(function(){ $(".searchs").keyup(function() { var searchbox = $(this).val(); var dataString = 'searchword='+ searchbox; if(searchbox=='') { $("#display").hide(); } else { $.
$(document).ready(function(){
$(".searchs").keyup(function() {
var searchbox = $(this).val();
var dataString = 'searchword='+ searchbox;
if(searchbox=='') {
$("#display").hide();
} else {
$.ajax({
type: "POST",
url: "searchs.php",
data: dataString,
cache: false,
success: function(html) {
$("#display").html(html).show();
}
});
}
return false;
});
$(".searchs").focus(function(){
var seachbox = $(searchbox).val();
if(seachbox != '') {
$("#display").show();
}
});
});
$(document).mouseup(function(e) {
if ($("#display").is(":visible") && $(e.target).parents$("#display").length == 0) {
$("#display").hide();
}
});
作为参考,我从你那里得到了剧本。我想做的是将mouseup函数添加到我的代码中。有人吗?如果你想将两者结合起来(尽管动作是一样的),你可以
$(document).ready(function(){
// ... whatever is already here
}).mouseup(function(e) {
if ($("#display").is(":visible") && $(e.target).parents$("#display").length == 0) {
$("#display").hide();
}
});
你通过7个问题来构建这个。现在,我想知道您真正拥有的是什么,因为我看到它在您的代码中。你想做什么?如果它不起作用,这意味着此时这些对象不存在或选择器错误。尝试在mouseup(函数(e){调试器中调试;