2014-06-13 54 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