2009-03-20 4 views
1

jQuery와 Prototype을 동시에 사용하려고합니다.jQuery와 Prototype 충돌

나는이 문제를 해결하기위한 해결책을 찾기 위해 몇 시간과 시간을 보냈습니다. 내가 찾은 가장 일반적인 방법은 http://docs.jquery.com/Using_jQuery_with_Other_Libraries입니다. 그러나 "jQuery.noConflict()"코드를 어떻게 배치하든 작동하지 않습니다.

아무도 도와 줄 수 있습니까? 여기

사전

에서

덕분에 $ 함수의 내부 jQuery 객체를 참조, 본질적으로 그렇게

(function($) { 

//$.noConflict(); // I don't below this is needed following this pattern 

$(function() // shorthand for $(document).ready() 
{ 
    $("#example").autocomplete(options); 
}); 


})(jQuery); 

처럼 jQuery 코드를 감싸 내 코드

<script type="text/javascript" src="/js/swfobject.js"> 
</script> 
<script type="text/javascript" src="/js/layerswitch.js"> 
</script> 
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> 
</script> 
<script type="text/javascript"> 
    _uacct = "UA-2351815-2"; 
    urchinTracker(); 
</script> 
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"> 
</script> 
<script type="text/javascript" src="/js/fadeLinks.js"> 
</script> 
<script> 
    jQuery.noConflict(); 
    jQuery(document).ready(function($){ 
     $("#example").autocomplete(options); 
    }); 
</script> 
<script src="js/prototype.js" type="text/javascript"> 
</script> 
<script src="js/scriptaculous/scriptaculous.js" type="text/javascript"> 
</script> 
<script src="js/recommended_items.js" type="text/javascript"> 
</script> 
<script type="text/javascript"> 
//<![CDATA[ 
Event.observe(window, 'load', function() { 
    var recommended_items = new RecommendedItems('recommended_items', <?="$store_id, $gift_registry_id" ?>); 
    recommended_items.setBaseURL('<?=$site_server . SITE_STANDARD ?>'); 
<?php if (THIS_PAGE == PRODUCT_PHP) { ?> 
    recommended_items.setProduct(<?="$product_id, $category_id" ?>); 
<?php }        ?> 
    recommended_items.fetchItems(); 
}); 
//]]> 
</script> 

답변

3

입니다

+0

jQuery (document) .ready로 전달 된 함수는 호출시 jQuery 객체를 가져옵니다. 따라서 함수 내부에서는 $이어야합니다. – Annan

+0

고마워요. 그러나 아직 끝나지 않았습니다. - " – Kev

+0

@Kev - Firebug로 디버깅 해 봤나? –

2

전화를 jQuery에 할당 할 수 있습니다. 변수에 noConflict()를 적용한 다음 JQuery를 사용하고자 할 때 전역 변수를 사용하십시오. 따라서 :

<script> 
    var $$ = jQuery.noConflict(); 
    jQuery(document).ready(function($){ 
     $$("#example").autocomplete(options); //jQuery selector 
     alert($("#example".val()); //prototype selector 
    }); 
</script> 
+0

$$는 DOM 요소의 CSS 선택자로 prototype.js에서 사용됩니다. –

+0

jquery doco에 따라 더 나은 기호 $ j가 있습니다. – ybakos