2017.1.4 jQuery中的data()方法和each()方法
来源:互联网 发布:人体测量尺寸数据 编辑:程序博客网 时间:2024/05/18 21:10
jQuery中的data()方法用于向被选元素提取数据,或者向被选元素附加数据
向被选元素提取数据语法:$(selector).data(name),name为规定要提取的数据名称
向被选元素附加数据语法:$(selector).data(name,value)
例如:
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <title>jQury.data()</title> <script src="lib/jquery/jquery.js"></script> <script src="lib/bootstrap/js/bootstrap.js"></script> <script> $(function(){ var $me=$(".me"); console.log($me.data("name")); var $you=$(".you"); $you.data("name","zhaoyu"); console.log($you.data("name")); }) </script></head><body><div class="me" data-name="ouyang"></div><div class="you" data-name="ouyang"></div></body></html>
jQuery遍历—each()方法
对 jQuery 对象进行迭代,为每个匹配元素执行函数。
<!DOCTYPE html><html lang="en"><head> <meta charset="utf-8"> <title>jQury.data()</title><script src="lib/jquery/jquery.js"></script><script src="lib/bootstrap/js/bootstrap.js"></script><script>$(function(){ $("li").each(function(i,ele){ //i为选择器的索引位置,ele为当前的元素,也可以用this代替 var $ele=$(ele); console.log($ele.text()); }) })</script></head><body><ul class="content"> <li>苹果</li> <li>香蕉</li> <li>菠萝</li> <li>桃子</li></ul></body></html>注意:这里的ele为DOM对象,并非jQuery对象,如果要调用jQuery中的方法就要将ele转化为jQuery对象。
0 0
- 2017.1.4 jQuery中的data()方法和each()方法
- Jquery中的each方法
- jQuery中的each方法
- Jquery中的each()方法
- 浅谈jquery中的each方法$.each、this.each、$.fn.each
- 数组的各种遍历方法和jQuery中的each方法
- jQuery中的each方法实例
- HTML5中的data-*属性和jQuery中的.data()方法使用
- HTML5中的data-*属性和jQuery中的.data()方法使用
- HTML5中的data-*属性和jQuery中的.data()方法使用
- 【jquery】find()方法和each()方法
- 【jquery】find()方法和each()方法
- jQuery中map()方法和each()方法
- jquery的each()方法
- jQuery中的$.each方法,怎么用?
- jquery each方法
- jquery each方法
- jQuery each方法
- summernote富文本域
- C/C++运算符重载
- 使用Navicat For Oracle连接Oracle数据库
- 0104 wrrkmigua ListPopupWindow的使用
- 隐私政策
- 2017.1.4 jQuery中的data()方法和each()方法
- Keil 汉字显示不正常,删除时要删两下
- 每天一个linux命令(3):pwd命令
- RecyclerView的各种版本兼容问题处理集锦
- 人生第一篇博客
- 光流定点程序梳理
- 用NGUI实现刮刮乐的效果
- 日请求过亿的Web系统PHP7升级实践
- X11算法 VS Scrypt算法