1

jQueryとPrototypeの両方を同時に使用しようとしています。

私はこの問題を解決するための解決策を探すのに何時間も費やしてきました。私が見つけた最も一般的な方法は、このhttp://docs.jquery.com/Using_jQuery_with_Other_Librariesです。ただし、「jQuery.noConflict()」コードをどのように配置しても機能しませんでした。

誰かがこれを手伝ってくれますか?

前もって感謝します

これが私のコードです

<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>
4

2 に答える 2

3

jQueryコードを次のようにラップします

(function($) {

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

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


})(jQuery);

本質的に、関数内のオブジェクトを$指しますjQuery

于 2009-03-20T22:35:23.340 に答える
2

jQuery.noConflict() への呼び出しを変数に割り当て、JQuery を使用するときにその変数を使用できます。そう:

   <script>
    var $$ = jQuery.noConflict();
    jQuery(document).ready(function($){
      $$("#example").autocomplete(options);  //jQuery selector
      alert($("#example".val());  //prototype selector
    });
</script>
于 2009-03-20T22:42:01.873 に答える