2012-08-02 32 views
0

我有一個帶有3個滑塊和一個彈出框的網頁。
對於我使用的滑動條jQuery.noConflict(),這樣工作正常。
但在彈出框的情況下,如果我使用jQuery.noConflict()它不起作用。
如果我不使用jQuery.noConflict(),那麼我的滑塊不會工作。jQuery.noConflict()不適用於彈出框

彈出HTML

<div id="popupContact"> 
    <a id="popupContactClose"><img src="close.gif" alt="close"/></a> 
    <div id="contactArea"></div> 
</div> 
<div id="backgroundPopup"></div> 

彈出的jQuery

var popupStatus = 0; 
function loadPopup(){ 
    if(popupStatus==0){ 
    $("#backgroundPopup").css({ 
     "opacity": "0.2" 
    }); 
    $("#backgroundPopup").fadeIn("slow"); 
    $("#popupContact").fadeIn("slow"); 
    popupStatus = 1; 
    } 
} 

function disablePopup(){ 
    if(popupStatus==1){ 
    $("#backgroundPopup").fadeOut("slow"); 
    $("#popupContact").fadeOut("slow"); 
    popupStatus = 0; 
    } 
} 

function centerPopup(){ 
    var windowWidth = document.documentElement.clientWidth; 
    var windowHeight = document.documentElement.clientHeight; 
    var popupHeight = $("#popupContact").height(); 
    var popupWidth = $("#popupContact").width(); 
    $("#popupContact").css({ 
    "position": "absolute", 
    "top": windowHeight/2-popupHeight/2, 
    "left": windowWidth/2-popupWidth/2 
    }); 
    $("#backgroundPopup").css({ 
    "height": windowHeight 
    }); 
} 

var $rp = jQuery.noConflict(); 
$rp(document).ready(function(){ 
    $rp("#buttonpop").click(function(){ 
    centerPopup(); 
    loadPopup(); 
    }); 
    $rp("#popupContactClose").click(function(){ 
    disablePopup(); 
    }); 
    $rp("#backgroundPopup").click(function(){ 
    disablePopup(); 
    }); 
    $rp(document).keypress(function(e){ 
    if(e.keyCode==27 && popupStatus==1){ 
     disablePopup(); 
    } 
}); 
}); 

注:該彈出jQuery是一個外部jQuery和我使用<script src="http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js" type="text/javascript"></script>也。

謝謝。

回答

2

如果您使用jQuery.noConflict(),那麼可以防止jQuery從別名jQuery$進行別名。但是,您的彈出式代碼仍在嘗試使用$

要麼參考jQuery,不$,或包裝你的代碼在一個封閉並引用$當封閉內的局部變量,即

(function($) { 
    //popup code here 
})(jQuery); 
+0

,如果我嘗試上述指令,那麼它的影響我的滑蓋還。 – RAN 2012-08-02 12:14:32