Rails每周闲碎(九): JavaScript
1. Caching multiple javascript into onejavascript_include_tag :all, :cache => true
javascript_include_tag "prototype", "cart", "checkout", :cache => "shop"
2. jQuery
jQuery is a fast and concise JavaScript Library that simplifies HTMLdocument traversing, event handling, animating, and Ajax interactionsfor rapid web development. jQuery is designed to change the way that you write JavaScript.
Rails默认使用的ajax框架是prototype,结合prototype,Rails提供了一些非常方便的prototypehelper方法,比如:remote_form等。如果在Rails中选择使用jQuery库,不用担心使用不了这些helper方法,因为jRails为这些方法提供了jQuery版本。
jRails is a drop-in jQuery replacement for Prototype/script.aculo.us on Rails. Using jRails, you can get all of the same default Rails helpers for javascript functionality using the lighter jQuery library.
用jQuery实现的一些工具也很好用,比如greybox。
3. prototype helper methods
It's strong by providing lots of helper method like observe_field, with lots of options like :success, :condition, :before.
如果使用JQuery,也不需要担心这些方法没法使用。JRails为这些方法实现了JQuery版本。
4. jquery的$(document).ready()
与window.onload的区别 : $(document).ready()是在DOM结构载入完后执行的,而window.onload是在所有文件都加载完后执行的。
5. jquery的serialize
Serializes a set of input elements into a string of data. http://docs.jquery.com/Ajax/serialize
页:
[1]