2009-08-04 26 views
10

有什麼辦法可以同時使用jquery和scriptaculous js文件嗎?同時使用jquery.js和scriptaculous.js文件?

我試圖實現cakephp框架的自動完成功能,它需要js文件,prototype.js,scriptaculous.js,effects.js和controls.js。

我也在我的應用程序中使用JQuery函數,它需要jquery.js文件。

如果我包含jquery.js文件,自動完成功能不起作用。但我也需要jquery.js文件來實現我的jQuery功能。

那麼有什麼方法可以同時使用js文件嗎?

+3

您是否看到此鏈接?:http://docs.jquery.com/Using_jQuery_with_Other_Libraries – Zed 2009-08-04 11:09:42

回答

22

您將需要啓用jQuery的無衝突模式,請參閱:

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

從上面的鏈接:

<html> 
<head> 
    <script src="prototype.js"></script> 
    <script src="jquery.js"></script> 
    <script> 
    jQuery.noConflict(); 

    // Use jQuery via jQuery(...) 
    jQuery(document).ready(function(){ 
     jQuery("div").hide(); 
    }); 

    // Use Prototype with $(...), etc. 
    $('someid').hide(); 
    </script> 
</head> 
<body></body> 
</html> 

但是,你仍然需要加載原型的是Scriptaculous上班。作爲一個建議,如果你只是(或者主要)使用其他庫來創建一個自動完成的小部件,你可能需要嘗試jQuery's autocomplete plugin

+0

非常感謝。它工作絕對好.. :) – Angeline 2009-08-04 11:29:05

1

做到既jQuery和Scriptaculous的最簡單的方法就是做:

var $j = jQuery.noConflict(); 

,並使用附加$ J而不是jQuery的 $。例如,

$j('#id')

相關問題