2014-06-13 56 views
-2

此代码适用于jQuery 1.8.0,但不适用于1.11.0等新版本。它使用的哪些功能已过时,我如何才能使其工作?我查看了文档,但无法在此代码中找到弃用列表中的任何功能。jquery 1.8.0弃用的功能

$(document).ready(function() { 

// Icon Click Focus 
$('div.icon').click(function(){ 
    $('input#search').focus(); 
}); 

// Live Search 
// On Search Submit and Get Results 
function search() { 
    var query_value = $('input#search').val(); 
    $('b#search-string').html(query_value); 
    if(query_value !== ''){ 
     $.ajax({ 
      type: "POST", 
      url: "../includes/search.php", 
      data: { query: query_value }, 
      cache: false, 
      success: function(html){ 
       $("ul#results").html(html); 
      } 
     }); 
    }return false;  
} 

$("input#search").live("keyup", function(e) { 
    // Set Timeout 
    clearTimeout($.data(this, 'timer')); 

    // Set Search String 
    var search_string = $(this).val(); 

    // Do Search 
    if (search_string == '') { 
     $("ul#results").fadeOut(); 
     $('h4#results-text').fadeOut(); 
    }else{ 
     $("ul#results").fadeIn(); 
     $('h4#results-text').fadeIn(); 
     $(this).data('timer', setTimeout(search, 100)); 
    }; 
}); 

}); 
+0

[.live()在1.7被废弃](http://api.jquery.com/live/) – mawburn

回答

2

'活'已被弃用。而不是'活'使用'开'。

$("input#search").on("keyup", function(e) { 
    // Set Timeout 
    clearTimeout($.data(this, 'timer')); 

    // Set Search String 
    var search_string = $(this).val(); 

    // Do Search 
    if (search_string == '') { 
     $("ul#results").fadeOut(); 
     $('h4#results-text').fadeOut(); 
    }else{ 
     $("ul#results").fadeIn(); 
     $('h4#results-text').fadeIn(); 
     $(this).data('timer', setTimeout(search, 100)); 
    }; 
}); 
+1

哇,我认为这是一个不好的问题。但非常感谢你的回答。有用。 – suyilmaz

+0

@suyilmaz,不客气。乐意效劳。 – RGS