te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - Multiple jQuery includes in a document - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Multiple jQuery includes in a document - Stack Overflow

programmeradmin2浏览0评论

I have a document which uses old jQuery and I need new jQuery for a particular plug-in. My document structure looks like this:

<html>
<head>
    <script type="text/javascript" src="jQuery.old.js"></script>
</head>
<body>
    <script>
        $("#elem").doSomething(); // use old jQuery
    </script>            
    <!-------- My plugin begins -------->
        <script type="text/javascript" src="jQuery.new.js"></script>
        <script type="text/javascript" src="jQuery.doSomething.js"></script>
        <script>
        $().ready(function(){
            $("#elem").doSomething();   // use new jQuery
        });
        </script>
        <div id="elem"></div>
    <!-------- My plugin ends ---------->
    <script>
        $("#elem").doSomething(); // use old jQuery
    </script>
</body>
</html>

I have googled for this question but found nothing that would look like my case (I need first to load old javascript (in the head) and THEN new (in the body). By the way, in the Firefox looks like old jQuery lib loads and scripts that depends on it works, but script that uses new version, and in IE and Chrome everything is exactly opposite.

I have a document which uses old jQuery and I need new jQuery for a particular plug-in. My document structure looks like this:

<html>
<head>
    <script type="text/javascript" src="jQuery.old.js"></script>
</head>
<body>
    <script>
        $("#elem").doSomething(); // use old jQuery
    </script>            
    <!-------- My plugin begins -------->
        <script type="text/javascript" src="jQuery.new.js"></script>
        <script type="text/javascript" src="jQuery.doSomething.js"></script>
        <script>
        $().ready(function(){
            $("#elem").doSomething();   // use new jQuery
        });
        </script>
        <div id="elem"></div>
    <!-------- My plugin ends ---------->
    <script>
        $("#elem").doSomething(); // use old jQuery
    </script>
</body>
</html>

I have googled for this question but found nothing that would look like my case (I need first to load old javascript (in the head) and THEN new (in the body). By the way, in the Firefox looks like old jQuery lib loads and scripts that depends on it works, but script that uses new version, and in IE and Chrome everything is exactly opposite.

Share Improve this question asked May 21, 2010 at 10:35 vytauxvytaux 2,5624 gold badges24 silver badges35 bronze badges 5
  • this is a very irrelevant question. We want to use Windows 7 to play one game and Windows Xp to play another – Starx Commented May 21, 2010 at 10:43
  • Why not just use the newer version alone? Don't think there will be backward patibility issues. – Checksum Commented May 21, 2010 at 10:47
  • @Starx, I don't think you understand what I want to do there. @Checksum, It's not possible to remove the old one version because I don't have access to edit that part of the page. So I have to find a way around. – vytaux Commented May 21, 2010 at 10:56
  • gutted - you should probably try to get the person who can edit that part of the page to change it, unless your providing something like ad content, in which case you might not want to use a library like jQuery. – digiguru Commented May 21, 2010 at 11:07
  • See stackoverflow./questions/2837351/… etc – bobince Commented May 21, 2010 at 11:38
Add a ment  | 

3 Answers 3

Reset to default 13

To start, you should try running all the plugins under the latest version of jQuery - you may find you can use just the one latest version.

If you cannot do this, you can run in patibility mode. Here is how.

<script src="jquery-1.3.2.js"></script>
<script>
    var jqueryA = jQuery.noConflict();
</script>
<script src="jquery-1.4.2.js"></script>
<script>
    var jqueryB = jQuery.noConflict();
</script>

You would need to call

jqueryB("#myelement").....

To use the alternate version.

You should use jQuery.noConflict();

See this example: http://web.enavu./daily-tip/using-multiple-versions-of-jquery-on-the-same-page/

As a rule of thumb, stick to one included jquery file. It's quite a large file, and there's no need to import multiple versions. I would opt for the latest version, which can be served from google or microsoft to speed up your server.

Note if you want the "doSomething" event to behave differently depending on where it's called in the page, you could try to bind the event differently. Check out the following example. As with yours, it calls the new version from within your plugin area on the page ready event - this might be later than you expected.

<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head>
<body>
     <div id="elem"></div>

    <script>
        var oldFunct = function (e,o) { alert("old jquery" + o); };
        var newFunct = function (e,o) { alert("new jquery" + o); };
        $("#elem").bind("doSomething", oldFunct);
        $("#elem").trigger("doSomething", ["1"]);

    </script>
        <script>
        $(document).ready(function(){
            $("#elem").bind("doSomething", newFunct);
            $("#elem").trigger("doSomething", ["2"]);
            $("#elem").bind("doSomething", oldFunct);
        });
        </script>


    <script>
        $("#elem").trigger("doSomething", ["3"]);
    </script>
</body>
</html>
发布评论

评论列表(0)

  1. 暂无评论