2014-01-06 115 views
1

我想更新我的代码,这与jquery 1.4.1很好地工作与jQuery 1.10.2。 我在谷歌搜索,但我没有找到我必须做什么改变。 我得到以下错误:
Uncaught TypeError: Object #<Object> has no method 'photoTagger'更新代码从jquery 1.4.1到1.10.2

这是我想更新函数的名称。

+0

您是否使用'photoTagger'自定义插件?同时向我们展示一些您想要更新的代码 – Satpal

回答

2

我会建议你不要更改整个代码,如果它不是必要的,因为许多代码依赖于jQuery库和一些功能也弃用,不支持最新版本。您可以在同一页面上使用多个jQuery文件。

<!-- load jQuery version 1.4.1 --> 
<script src="jquery-1.4.1.js" type="text/javascript"></script> 
<script type="text/javascript"> 
var $jQuery1_4 = $.noConflict(true);// Here you must need to pass true 
            //else it will only free $ variable 
            //and using jQuery with blow libraries 
            //cause conflict 
</script> 

//you must load second library later after initializing 
//first instance of version and freeup jQuery keyword 
//else jQuery keyword will 
//cause conflict it you uplaoded both files. 

<!-- load jQuery version 1.10.0 --> 
<script src="jquery-1.10.0.js" type="text/javascript"></script> 
<script type="text/javascript"> 
var $jQuery1_10 = $.noConflict(true); 
</script> 

//so now here $ and jQuery both cannot be used 

//using $jQuery1_10 will call version 1.10.0 library code 
$jQuery1_10("div p").show(); 

//using $jQuery1_9 will call version 1.4.1 library code 
$jQuery1_4("div p").show(); 
2

您只需要使用jQuery的迁移文件,该文件可以在这里找到: http://code.jquery.com/

然后,您可以使用最新的jQuery版本和旧的插件/ jQuery代码仍然可以工作,如:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> 
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
0

在这种情况下,问题不是jQuery的verisons之间的不相容性,这是加载顺序不正确的JavaScript和jQuery文件和功能调用。 我解决了这个问题,你的答案对我有帮助。感谢帮助!