2012-03-09 19 views
0

即时通讯使用jquery执行现场自动建议下拉与我的网站上的搜索栏。但有一个问题IM,我该如何停止自动从显示提示框时有从jQuery例子信息如何停止我的自动建议下拉搜索前显示

enter image description here

////// HTML表单的jQuery

除了在场上心不是什么
 <div id="searchbox_largesearcher_bg"> 

     <div id="searchbox_signalbg"></div> 

     <form id="large-searcher" action="" method="post"> 

     <input name="large-search-form" id="large-search-form" type="text" size="35" onfocus="if (this.value == 'Search A Genre e.g. &quot;Hip-Hop&quot;') this.value = '';" onblur="if (this.value == '') this.value = 'Search A Genre e.g. &quot;Hip-Hop&quot;';" maxlength="35" value="Search A Genre e.g. &quot;Hip-Hop&quot;"/> 

     <input name="login" id="search_btn" class="search" type="submit" value="" /> 

     <div id="searchbox_searchicn"></div> 
     </form> 

     </div> 

     <div class="dropdown"> 

      <ul class="results"></ul> 

     </div> 

////// CSS

.dropdown { 
    -moz-border-bottom-colors: none; 
    -moz-border-image: none; 
    -moz-border-left-colors: none; 
    -moz-border-right-colors: none; 
    -moz-border-top-colors: none; 
    background-color: #F5F5F5; 
    border-radius: 5px 5px 5px 5px; 
    box-shadow: 0 1px 2px -1px #000000; 
    margin-left: 32px; 
    margin-top: -12px; 
    padding: 0; 
    position: absolute; 
    width: 460px; 
    z-index: 99; 
    } 


.results { 
    border: 1px solid #A2A1A1; 
    border-radius: 5px 5px 5px 5px; 
    list-style: none outside none; 
    padding-bottom: 7px; 
    padding-top: 7px; 
    width: 458px; 

    } 

.results li{ 
    border-bottom: 1px solid #EDEDED; 
    color: #A8A8A8; 
    cursor: pointer; 
    font-family: helvetica neue,helvetica,arial sans-serif; 
    margin-left: 20px; 
    margin-right: 20px; 
    padding-bottom: 14px; 
    padding-left: 25px; 
    padding-top: 10px; 

    } 

.results li:hover{ 
    background: none repeat scroll 0 0 #EEEEEE; 
    color: #A8A8A8; 

    } 

//////// jQuery的自动提示

<script type="text/javascript"> 

// Large Index Page Live Returns Searcher 

$(document).ready(function(){ 
$('#large-search-form').keyup(function() { 

var search_term = $(this) .attr('value'); 

$.post('inc/resultsgrabber.php', {search_term:search_term}, function (data) { 

$('.results').html(data); 

$('.results li').click(function() { 
    var result_value = $ (this) .text(); 
    $('#large-search-form').attr('value', result_value); 
    $('.results').html(''); 
    }); 


}); 


}); 

}); 
+0

你能提供css – mgraph 2012-03-09 10:36:03

+0

@mgraph css已被添加 – Farreal 2012-03-09 10:45:22

回答

0

原来是一个CSS问题我有填充和边界在一些错误的地方。 jquery代码完全没问题。对于那个很抱歉。

1

最好的方法是检查在ajax调用之后,data响应中是否有任何数据。

.results { display:none } 


$.post('inc/resultsgrabber.php', {search_term:search_term}, function (data) { 
    if (data == '') { 
    $('.results').html(data); 
    . 
    . 
    . 
    . 
    . 
    } 
}); 
相关问题