How would you go about for switching a site from Prototype to jQuery

后端 未结 1 1405
南方客
南方客 2021-01-05 02:56

I have written a site in Prototype but want to switch to jQuery. Any ideas on how best make the switch?

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-05 03:17

    Personally, I like to take things in steps, so I would start by using both, like this:

    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').hide();
    

    That way you don't have to convert all your old code at once, but can start using jquery on new stuff, and migrate your old Prototype code when ever it's convenient. I don't know the size of your project, so I can't say whether or not this applies to you, but Spolsky had a great article about "The big rewrite" and why it's such a bad idea in Things you should never do, Part 1. It's well worth a read!

    For more on using jquery with Prototype, see Using jQuery with other libraries in the jquery docs.

    0 讨论(0)
提交回复
热议问题