2012-12-03 43 views
-3

我想結合JS功能,但這不起作用。有人對我的代碼有建議嗎?結合JS功能mouseup

$(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函數添加到我的代碼中。任何人?

+1

您通過7個問題建立這樣的。現在,我想知道你真的試過了什麼 – Alexander

+0

正如我所看到的那樣*它代表你的代碼。你想做什麼? – i100

回答

0

,如果你想將二者結合起來(雖然行動將是相同的),你可以

$(document).ready(function(){ 
// ... whatever is already here 
    }).mouseup(function(e) { 
     if ($("#display").is(":visible") && $(e.target).parents$("#display").length == 0) { 
     $("#display").hide(); 
     } 
    }); 
+0

我已經試過..但沒有工作... –

+0

如果它不起作用,這意味着目前這些對象不存在或選擇器是錯誤的。嘗試在mouseup中調試(function(e){debugger; – i100