尚能饭否|技术越来越新,我对老朋友 jQuery 还是一如既往热爱
前言
最近在搭建完善自己的博客,需要用到一些页面样式之类的,就特意问了一下女朋友一个问题,关于 Web 前端开发,jQuery 现在过时了嘛?她毅然决然告诉我,那是我们前端现在的鄙视链。是的,不可否认,现在框架盛行,jQuery 早已被 GitHub 所遗弃。我依稀记得,两年前,我学前端知识,觉得这个框架真的很好,以后有时间,一定要好好学一下它。也就这么点时间,它早已淡出了前端开发者的视线。不过呢,我身为后端开发,也就是一个新人于前端来说,所以我还是很喜欢 jQuery 的思想,因为让我直接理解 Vue/React 的话,还是需要大量时间的,所以认为 jQuery 是一个不错的过渡选择,也可以学习下前端编程思想,我看中了它的人性化以及可读性很强,对于我们来说也很简单,所以本文带大家一起回忆那些 jQuery 的点点滴滴,也为我们前端知识打个牢固的技术基础。
1、了解 jQuery
「背景:」
Query 查询的意思,jQuery 就是用 javascript 更方便的查询和控制页面组件
「宗旨:」
设计宗旨:Write Less,Do More,即提倡写更少的代码,做更多的事
「简介:」
jQuery 封装 JavaScript 常用的功能代码,提供一种简便的 JavaScript 设计模式,优化 HTML 文档操作、事件处理、动画设计和 Ajax 交互
支持链式写法,对 css 样式支持接近完美
集 JavaScript、CSS、DOM、Ajax 于一体的强大框架体系
2、jQuery 的基本功能
「功能:」

3、搭建 jQuery 开发环境
「流程:」
准备两份文件如下:



4、jQuery 选择器
「分类:」
基本选择器、层次选择器、过滤选择器(表单选择器)
「基本选择器:」

案例:通过不同的选择器来控制页面元素的展示






「层次选择器:」

案例:通过不同的选择器来控制页面元素的展示




「过滤选择器:」

简单过滤器是使用最广泛的一种,ps:隔行变色


可见性过滤选择器,根据元素是否可见的特征获取元素,ps:寻找页面被隐藏的元素


属性过滤选择器,根据元素的某个属性获取元素,如 ID 号或匹配属性值的内容,并以“[”号开始,以“]”结束,ps:最后一个是复合属性选择器


子元素过滤选择器,注意:nth-child 索引从 1 开始


表单选择器,专为表单量身打造,通过它可以在页面中快速定位某表单对象


表单对象属性过滤选择器,通过表单中的某对象属性特征获取该类元素,如:enabled、disabled、checked、selected 属性


「选择器综合案例:」
整体如下:




代码如下

5、jQuery 对象和 DOM 对象
「关系:」
jQuery 对象就是通过 jQuery 包装 DOM 对象后产生的对象
注意:jQuery 对象是包装 DOM 对象后产生的,但是 jQuery 无法使用 DOM 对象的任何方法,同理 DOM 对象也不能使用 jQuery 里的方法
「具体转换:」
jQuery 和 DOM 对象互转
结语
本篇关于 jQuery 的的介绍就先到这里结束了,后续会出 jQuery 动画、Ajax、jQuery 操作 DOM 以及 jQuery 事件的文章,敬请期待,谢谢大家支持!

版权声明: 本文为 InfoQ 作者【浅羽技术】的原创文章。
原文链接:【http://xie.infoq.cn/article/7e96b4c461092911b2d45d12e】。文章转载请联系作者。
评论