Jquery keyup无法在Android上运行

时间:2012-05-14 09:02:27

标签: javascript jquery android keyup

我没有在iPhone上测试过这段代码,但我确信(测试过)它不能在Android手机上运行:

 $('#search').live('keyup',function(key){
          if(key.which == 13){
            /*ANIMATE SEARCH*/
            _key = $(this).val();
            $("#wrapper").html("");
                $('#wrapper').hide(0).load('results.html').fadeIn(800);
                $('#search-fade').val(_key).fadeIn();
          }
      });

更好地解释:

我有一个简单的

<input type="text" name="search" id="search"/>

不知道为什么但这段代码在Android手机上无法正常使用

任何想法?

2 个答案:

答案 0 :(得分:9)

$(document).on('keyup','#search', function() {
   // code
});

$(document).delegate('#search', 'keyup', function() {
    // code
});

您还可以看到here

答案 1 :(得分:4)

我的解决方案(使用jQuery 1.7.1):

$('#search').live('input paste', yourFunction)

提示:

使用.on()代替.live(),因为:

      
  • .on()更快
  •   
  • .live()已弃用

jQuery 1.7+ .on() vs .live() Review

试试这个:

$(document).on('input paste', '#search', yourFunction)