2014-03-25 37 views
0

以下代码与jquery 1.7.2一起工作正常。但它不与jQuery 1.9.1。它给人以“遗漏的类型错误错误。对象的翻译:有没有一种方法‘活’。jQuery 1.9.1没有方法实时错误

我怎样才能解决这个问题?

在此先感谢。

enter image description here

<script> 
$(document).ready(function(){ 

    var tablecont = $("#tablesorter1"); 
    var module = "category"; 

    function updateitem() 
    {  
     $.ajax({ 
      type: "POST", 
      url: "http://localhost/tangen2014/index.php/category/admin/Ajaxgetupdate", 
      complete: function(data) 
      { 
       tablecont.html(data.responseText); 
      } 
     }); 
    } 

     //on submit event 
    $(".changestatus").live('click', function(event){ 
     event.preventDefault(); 
     var href = $(this).attr("href"); 
     var id =href.substring(href.lastIndexOf("/") + 1); 
     $.ajax({ 
      type: "POST", 
      url: "http://localhost/tangen2014/index.php/kaimonokago/admin/changeStatus"+"/"+module+"/"+id, 
      complete: function() 
      { 
       updateitem(); 
      } 
     }); 
    }); 
}); 
</script> 
+0

[jQuery live()适用于jQuery 1.8.3及更高版本,但不适用于1.9.1或2.0](http://stackoverflow.com/questions/16543309/jquery-live-works-with-jquery -1-8-3,但不是与1-9-1或2-0) – Jacob

回答

2

upgrade guide

的.live()方法,因为jQuery的1.7已经被废弃,并已在1.9移除 。我们建议您升级代码来使用。对()方法 代替

所以你需要使用.on()这里:

$('#tablesorter').on('click', ".changestatus", function(event){ 
    // Your code here 
}); 

这也是更好地委派事件到最近的静态父母代替的文档级别以获得更好的性能。

+0

我认为没有任何重要的*表现*理由选择一个亲密的父母,但也有其他很好的理由。 Bubbling是在原生浏览器代码中完成的,所以我怀疑在文档中一直冒泡有任何可衡量的差异。 – Pointy

1

.live()方法已被弃用,因为像永远一样,并且它在1.9中完全被抽出。

使用:

$(document).on('click', ".changestatus", function(event){ 

它不$(document);它可以是任何方便的容器元素。也就是说,任何元素都是“.changestatus”元素的父元素。

.live()方法是一个不错的主意。有一段时间有.delegate(),它更像现代一体机.on()的三个参数。

相关问题