久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在頁面上包含兩個版本的 jQuery 而不會影響舊插件

Include two versions of jQuery on a page without affecting old plugins(在頁面上包含兩個版本的 jQuery 而不會影響舊插件)
本文介紹了在頁面上包含兩個版本的 jQuery 而不會影響舊插件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我們的 drupal 站點使用我們尚未升級的 jQuery 版本 1.2.1 運行.

Our drupal site runs with jQuery version 1.2.1 which we have not upgraded.

問題是這樣的:

我們需要添加一個名為 jQuery Tokeninput 的新插件,但它只適用于最新的 jQuery 版本.我們嘗試在舊版本中添加最新的 jQuery 版本,但結果很奇怪.

We need to add a new plugin named jQuery Tokeninput, but it's working only in latest jQuery versions. We tried adding the latest jQuery version with old version, but it produces weird results.

我的問題是,如何在不影響舊 jQuery 插件的情況下包含最新的 jQuery 文件?

My question is, how to include the latest jQuery file without affecting the old jQuery plugins?

推薦答案

方法一:(推薦)

你可以這樣做:

<script type='text/javascript' src='js/jquery_1.7.1.js'></script>   
<script type='text/javascript'>  
 // In case you wonder why we pass the "true" parameter,
 // here is the explanation:
 //   - When you use jQuery.noConflict(), it deletes
 //     the "$" global variable.
 //   - When you use jQuery.noConflict(true), it also
 //     deletes the "jQuery" global variable.
 var $jq = jQuery.noConflict(true);  
</script>  
<script type='text/javascript' src='js/jquery_1.2.1.js'></script> 

這樣,當你想要用新版本的 jquery 而不是 $ 制作的東西時,請使用 $jq.

And this way when you want something made with the new version of jquery instead of the $ use $jq.

$jq('.selector').on('click', function(){  
    //do something  
});

方法 #2:(可能會破壞您網站上的內容 - 不推薦)

在您的 template.php 文件中:

<?php
function {theme_name}_preprocess(&$vars, $hook) {
if (arg(0) != 'admin' && $hook == "page") {
// Get an array of all JavaScripts that have been added
$javascript = drupal_add_js(NULL, NULL, 'header');

// Remove the original jQuery library
unset($javascript['core']['misc/jquery.js']);

// Add in our new jQuery library
// We do it this way to keep the includes in the same order
$core = array(
//Alternative jQuery
drupal_get_path('theme', '{theme_name}').'/js/libs/jquery-1.7.1.min.js' => array(
'cache' => TRUE,
'defer' => FALSE,
)
);

// Merge back into the array of core JavaScripts
$javascript['core'] = array_merge($javascript['core'], $core);

// Rerender the block of JavaScripts
$vars['scripts'] = drupal_get_js(NULL, $javascript);
}
}

確保只在您網站的前端執行此操作.如果它們依賴于 Drupal 的 jQuery 版本,它可能會弄亂管理工具欄.

這篇關于在頁面上包含兩個版本的 jQuery 而不會影響舊插件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

jQuery/JavaScript Library for avatar creation?(用于創建頭像的 jQuery/JavaScript 庫?)
How to do following mask input problem?(如何做以下掩碼輸入問題?)
Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 設置值/標簽的問題)
how to unit-test private methods in jquery plugins?(如何對 jquery 插件中的私有方法進行單元測試?)
stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 為垂直滾動網站配置偏移量/對齊元素?)
jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽輸入插件.當文本框獲得焦點時選擇所有內容)
主站蜘蛛池模板: 国产视频综合 | 国产美女高潮 | 综合色在线 | 自拍视频网站 | 欧美色a v| 国产精品18久久久 | 特黄特黄a级毛片免费专区 av网站免费在线观看 | 中文字幕免费中文 | 欧美日韩精品国产 | 精品一二区 | 天天摸天天干 | 国产一区精品 | 99亚洲综合| 91免费视频观看 | 久久久精品日本 | 91啪亚洲精品 | 五月激情综合网 | 精品九九九| 欧美日韩精品久久久免费观看 | 你懂的av| 亚洲一区视频在线播放 | 久久国内精品 | 亚洲精品自在在线观看 | 亚洲欧洲精品一区 | 偷拍自拍网 | 99在线免费观看 | 国产精品久久久久久久久久久久 | 免费看91| 你懂的在线视频播放 | 91亚洲欧美 | www.色婷婷 | 国产欧美一区二区三区在线看 | 欧美激情国产日韩精品一区18 | 日日日日日日bbbbb视频 | 午夜影视大全 | 亚洲va国产日韩欧美精品色婷婷 | 少妇午夜一级艳片欧美精品 | 欧美一区二区三区视频 | 午夜影院在线观看 | 欧美午夜精品 | 99精品国产一区二区青青牛奶 |