I used to use jquery for the interface, and now we have to use a lot of Ajax effects to switch to rails with prototype
Because jquery uses a lot, change the frame is similar, but the details of a lot of different ...
1.dom Loading aspect:
jquery has the DOM ready method, delaying the binding of the JS function to know that the DOM tree is complete (if this function is not available, bindings such as event functions of some element may be faulted):
$ (document). Ready (function () {});
But prototype is not ... Have to find their own unofficial expansion, inconvenient, this basic function, such an important function, do not know why the delay to add to the core library
2.path Lookup, Dom positioning aspect
jquery's Dom lookup is consistent with CSS positioning, it is very convenient to use, which is one of his highlights and advantages
$ ('. Func #select_all '). Click (Function ()
$ (this). Parent (' div '). Parent (' div '). Find (' li. CheckBox input:checkbox ')
Prototype only find a single Dom object conveniently--$ (ID)
The trouble is to separate the individual and the array, if you find many objects under a path
Get $$ (' div. right_contact '), this style is still to locate a type of object
Rather than using a path lookup, this is less convenient and conceptually consistent than jquery
3. function, Event binding
For example, the class for Right_contact div binding Click Highlight Event, prototype writing is:
Copy Code code as follows:
$$ (' div. right_contact '). each (function (item) {
Item.observe (' click ', Function (event) {
New Effect.highlight (item,{duration:2.0,startcolor: ' #ffff99 ', EndColor: ' #fffffff ', Restorecolor: ' #fffffff '});
});
});
If it's jquery, it's a lot simpler:
$ ('. Right_contact '). Click (function () {
$ (this). Toggleclass (' hilight ');
})
I have used many frameworks, the most impressive one is called Hge game engine Framework, encapsulated a lot of low-level detail and implementation methods, and then he said: You could create everything from a simple puzzle to advanced mul tilayered platformer or strategy without even thinking of any non game code
A good framework should be to focus attention on business logic rather than technical features, and in design mode, jquery is superior to prototype, and the most typical example is to prototype a all-inclusive observe method if you want to click on the trigger function. Then go to register the click event
and jquery has the Item.click function ... Observe is inclusive, but jquery's practice of specifically creating proprietary functions for the most commonly used events makes people more focused on business logic ...