-3

我想组合 JS 函数,但这不起作用。有人对我的代码有建议吗?

$(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();
  }
});

作为参考,我从http://jsfiddle.net/bqQqN/15/获得了该脚本。我想要做的是将 mouseup 函数添加到我的代码中。任何人?

4

1 回答 1

0

如果您想将两者结合起来(尽管操作相同),您可以

    $(document).ready(function(){
// ... whatever is already here
    }).mouseup(function(e) {
      if ($("#display").is(":visible") && $(e.target).parents$("#display").length == 0) {
        $("#display").hide();
      }
    });
于 2012-12-03T08:12:11.220 回答