0
要隱藏點擊一個div上我用要停止document.click功能鍵上最多
$('#display').click(function(e){
e.stopPropagation();
});
$(document).click(function(){
$('#display').slideUp();
});
現在這一頁我想使函數document.click其餘工作僅如果用戶不打字文本框中帶有ID「mse」的任何文本。
<input type="text" id="mse" name="search">
我想是這樣的:
$(document).click(function(){
if($("#mse").keyup()){
//do nothing
}else{
$('#display').slideUp();
}
});
不過,這並不奏效。
幫我解決這個問題。
我總代碼:
$(document).ready(function(){
$("#mse").keyup(function()
{
var searchbox = $(this).val();
var dataString = 'searchword='+ searchbox;
if(searchbox=='')
{}
else
{
$.ajax({
type: "POST",
url: "search.jsp",
data: dataString,
cache: false,
success: function(html)
{
$("#smartscreen").html(html).show();
}
});
}return false;
});
$('#mse').focus(function(){
$('#display').css("display", "block");
});
$('#display').click(function(e){
e.stopPropagation();
});
});
$(document).click(function(e){
$('#display').slideUp();
});
的點擊不應該只如果文本框爲空,或者只在用戶沒有輸入當前工作的事(即點擊按鍵同時)? – techfoobar
這種情況下的邏輯(至少是解釋它的方式)沒有意義。您要麼輸入要麼點擊。不是都。當你開始點擊鼠標時,你的手會在什麼位置輸入一個單詞? – Deryck
「輸入任何文字」對你來說意味着什麼? (A)重點在你提到的領域; (B)一個或多個鍵實際上是關閉的,即,沒有相應的鍵盤鍵發生鍵入事件; (C)該領域不是空的; (D)在最後x毫秒內在該字段中出現擊鍵; (E)以上全部;(F)以上都不是。 – nnnnnn