JQuery和Prototype区别小结
来源:互联网 发布:网络上p是什么意思 编辑:程序博客网 时间:2024/04/29 02:54
jQuery使用得比较顺手也比较喜欢,不得已也要用Prototype,小小整理下区别。。
页面载入
// JQuery
- $ ( document ). ready ( function () {
- // Code
- });
// JQuery Shorthand
- $ ( function () {
- // Code
- });
// Prototype
- document . observe ( 'dom:loaded' , function () {
- // Code
- });
根据ID获取
// JQuery
- $ ( "#idname" );
// Prototype
- $ ( "idname" );
根据类名
// JQuery
- $ ( ".classname" );
// Prototype
- $$ ( '.classname' );
根据第一个符合的类名
// JQuery
- $ ( ".classname:first-child" );
// Prototype
- $$ ( '.classname' )[ 0 ];
根据ID绑定监听事件
// JQuery
- $ ( "#item" ). bind ( 'click' , function () {
- // Code
- });
- // JQuery Shorthand
- $ ( "#item" ). click ( function () {
- // Code
- });
// Prototype
- $ ( "#item" ). observe ( 'click' , function () {
- // code
- });
根据符合的类名绑定监听事件
$(".classname").bind('click',function(){
- // code
- });
- // JQuery Shorthand
- $ ( ".classname" ). click ( function () {
- // code
- });
// Prototype
- $$ ( ".classname" ). invoke ( 'observe' , 'click' , function () {
- // code
- });
结束终止事件
// JQuery
- $ ( "#id" ). click ( function () {
- //code
- return false ;
- });
// Prototype
- $ ( "id" ). observe ( 'click' , function ( e ) {
- //code
- Event . stop ( e );
- });
处理观察的元素
// JQuery
- $ ( '#idname' ). click ( function () {
- this . hide (); // Hide the item clicked
- });
// Prototype
- $ ( 'idname' ). observe ( 'click' , function ( e ) {
- el = e . findElement ;
- el . hide (); // hide the item clicked
- });
根据ID操作类名
// JQuery
- $ ( '#id' ). addClass ( 'red' );
- $ ( '#id' ). removeClass ( 'red' );
// Prototype
- $ ( 'id' ). addClassName ( 'red' );
- $ ( 'id' ). removeClassName ( 'red' );
根据类名操作类名。。
// JQuery
- $ ( '.class' ). addClass ( 'red' );
- $ ( '.class' ). removeClass ( 'red' );
// Prototype
- $$ ( '.class' ). invoke ( 'addClassName' , 'red' );
- $$ ( '.class' ). invoke ( 'removeClassName' , 'red' );
AJAX请求和JSON应用
$.get(url,function(data){ alert(data . name );
- }, 'JSON' );
// Prototypenew Ajax . Request ( url , {
- method : 'get' ,
- onSuccess : function ( transport , json ) {
- alert ( json . name );
- }
- });
可以得出结论:jQuery和Prototype大部分是极为相似的,多用几次就都熟了。。
作者: Sjolzy
地址: http://sjolzy.cn/Difference-between-JQuery-and-Prototype-Summary.html
- JQuery和Prototype区别小结
- [ jQuery ] jQuery.fn和jQuery.prototype区别!
- jQuery.fn和jQuery.prototype区别介绍
- jQuery.fn和jQuery.prototype区别介绍
- jquery和prototype.js的区别
- jquery和prototype.js的区别
- jQuery.fn和jQuery.prototype区别介绍 (赞)
- jQuery插件开发及jQuery.extend函数详解和jQuery.fn与jQuery.prototype区别
- jQuery插件开发及jQuery.extend函数详解和jQuery.fn与jQuery.prototype区别
- jQuery插件开发及jQuery.extend函数详解和jQuery.fn与jQuery.prototype区别
- zepto和jquery的区别小结
- jquery和prototype冲突解决
- jquery和prototype冲突解决
- jquery和prototype冲突问题
- prototype和jquery冲突 解决方法
- jquery和prototype冲突解决
- Jquery和prototype冲突问题
- jquery和prototype冲突解决
- 好图像代码处理个人网站
- 浅谈C中的malloc和free
- sql语句总结
- Android数据存储之Shared Preferences
- 选择正确的C/C++ Runtime Library
- JQuery和Prototype区别小结
- 关于edian大小端模式
- 优化网站的五种方法
- velocity实现页面静态化
- 提供一个网页抓取hao123手机号码归属地的例子
- 移动终端上看word文档
- 2012年4月11日OFDM学习笔记
- XNA--3D Coordinate Systems and Projections
- LFU缓存