论坛首页 Web前端技术论坛

jQuery 与 prototype 共存

浏览 9739 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-04-09  
方式一:
 
<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').style.display = 'none';
   </script>
 </head>
 <body></body>
 </html>

方式二:
<html>
 <head>
   <script src="prototype.js"></script>
   <script src="jquery.js"></script>
   <script>
     var $j = jQuery.noConflict();
     
     // Use jQuery via $j(...)
     $j(document).ready(function(){
       $j("div").hide();
     });
     
     // Use Prototype with $(...), etc.
     $('someid').style.display = 'none';
   </script>
 </head>
 <body></body>
 </html>

方式三:
<html>
 <head>
   <script src="prototype.js"></script>
   <script src="jquery.js"></script>
   <script>
     jQuery.noConflict();
     
     // Put all your code in your document ready area
     jQuery(document).ready(function($){
       // Do jQuery stuff using $
       $("div").hide();
     });
     
     // Use Prototype with $(...), etc.
     $('someid').style.display = 'none';
   </script>
 </head>
 <body></body>
 </html>
   发表时间:2007-04-09  
我使用的是 $j ,下一步计划逐步的将 prototype 的代码逐渐移除,
没有 namespace 总感觉不太好。
0 请登录后投票
   发表时间:2007-04-10  
JSI的解决方法:

1。不同脚本中使用。分别申明依赖即是,不会冲突:


2。页面上直接使用


js 代码
 
  1. <html>    
  2. <head>    
  3. <script src="boot.js"></script>    
  4. <script>  
  5. var $j = $import("org.jquery.$");  
  6. var $p= $import("net.nioc.prototype.$");  
  7.   
  8. //Use jQuery via $j(...)    
  9. $j(document).ready(function(){    
  10.        $j("div").hide();    
  11.  });   
  12.   
  13. // Use Prototype with $p(...), etc.    
  14. $p('someid').style.display = 'none';    
  15.   
  16. </script>    
  17. </head>    
  18. <body></body>    
  19. </html>    
0 请登录后投票
论坛首页 Web前端技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics