简体   繁体   English

如何获得较旧的jQuery代码以与较新版本的jQuery一起使用?

[英]How can I get older jquery code to work with newer versions of jquery?

Related: How do I run different versions of jQuery on the same page? 相关: 如何在同一页面上运行不同版本的jQuery?


I have a pages that uses a lot of jquery, I have a drag and drop that saves position into mysql DB also. 我的页面使用了很多jquery,也有拖放操作,也可以将位置保存到mysql DB中。 My jquery file is about 2 years old and today I tried to use a newer version because there is a script I am wanting to use but it only works with newer version within the past year of jquery. 我的jquery文件大约有2年的历史,今天我尝试使用一个较新的版本,因为有一个我想使用的脚本,但该脚本仅在jquery的过去一年中可用于较新的版本。

After I put in the newer version of jquery, my drag and drop does not work, everything else work on my page except my drag and drop code. 放入较新版本的jquery之后,我的拖放无法正常工作,除拖放代码外,其他所有内容都在我的页面上正常工作。 It partially works. 它部分起作用。

My page has 2 columns and you can drag items across the 2 colums but now it only drags on the left column and items in the right colum will not move. 我的页面有2列,您可以在2个列中拖动项目,但是现在它只能在左侧列中拖动,而右侧列中的项目将不会移动。

Items in the left column that do move will not find a place to drop to so on release the item is lost. 左列中确实移动的项目将找不到放置的位置,以便在释放该项目时将其丢失。 The ajax portion of my code is still working because when I "lose" an item it update the DB and that items ID number will be missing from my list of items on that page. 我的代码的ajax部分仍然有效,因为当我“丢失”一个项目时,它将更新数据库,并且该页面上我的项目列表中将缺少项目ID号。

How can I get older jquery code to work? 我怎样才能使旧的jQuery代码正常工作?

Here is my code 这是我的代码

<script>
var _x;
var _y;
var _pos;
if(document.all){document.body.onload=b_onload;}
else{document.body.setAttribute("onload","b_onload()");}
function b_onload(){
    $('#columns td.portlet_td').each(function(i){
        $(this).children("br").remove();
    });
    $('#columns td.portlet_td').Sortable(
        {
            accept: 'portlet',
            helperclass: 'sort_placeholder',
            activeclass :   'sortableactive',
            opacity: 0.7,
            tolerance: 'touch',
            handle:'.drag-handler',

            onStop:function(){

                var x = getPos();

                if(!$("#lgif").get(0)){
                    $('<i'+'mg id="lgif" src="images/loading.gif" style="display:block;position:absolute;top:500px;left:50%;" />').appendTo('body');
                }

                var __top = (document.body && document.body.scrollTop)?(document.body.scrollTop):((document.documentElement && document.documentElement.scrollTop)? document.documentElement.scrollTop: 0);

                $("#lgif").css({top:__top+'px'});

                $("#lgif").show();
$.getJSON(
    '/member/beta/saveposition.php',
    {
        uid:(USER.ID),
        position:x
    },
    function(json){
        $("#lgif").hide();
    }
);
            }
        }
    );



};
function resetPos(){
    $.getJSON(
        '/member/beta/saveposition.php',
        {
            uid:(USER.ID),
            position:"0:0|0:1|0:2|0:3|0:4|0:5|0:6|1:7|1:8|1:9|1:10|1:11|1:12|1:13|1:14|1:15|1:16|"
        },
        function(json){
            $("#lgif").hide();
        }
    );
}
function getPos(){
    _pos="";
    $('#columns td.portlet_td').each(function(i){
        _x=i;
        $(this).children(".portlet").each(function(j){
            _y=j;
            var index = this.getAttribute("id").split('id')[1] - 100;
            var pos=_x+":"+index;
            _pos+=pos+"|";
        });
    });
    return _pos;
}
</script>

Please also note that my jquery version that works correctly requires another file called interface, this interface file does not work with the new jquery version so maybe the new jquery needs something else added for drag and drop to work? 另请注意,要正常工作的我的jquery版本需要另一个名为interface的文件,该接口文件不能与新的jquery版本一起使用,因此也许新的jquery需要添加其他内容才能进行拖放工作?

Since you never said what version of JQuery you were using when that was made, we have no point of reference to see how much has actually changed since then. 由于您从未说过在创建JQuery时使用的是哪个版本,因此我们没有参考资料可以查看自那时以来实际发生了多少变化。 Your best bet is to just rewrite it, a very long list of changes have occurred since any old version of JQuery. 最好的选择就是重写它,自从任何旧版本的JQuery以来,已经发生了很长的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM