jquery each()
来源:互联网 发布:说淘宝店铺认证 编辑:程序博客网 时间:2024/06/13 04:45
<p>段落1</p>
<p>段落1</p>
<div>div1</div>
<div>div2</div>
$(function() {
//去除空格
var string=" d ";
//alert(string.trim().length);
//alert($.trim(string).length);
//this在each中是dom对象
//回调函数不加参数,使用this
$("p").each(function() {
$(this).click(function() {
alert($(this).html());
});
});
//遍历一组dom元素:第一个为对象的成员或数组的索引,第二个为对应变量或内容
$("div").each(function(index, obj) {
//alert(index+"----"+$(obj).text());
});
//遍历数组,回调函数第一个参数是下标,第二个参数是数组元素
var arr=[0,1,2];
$.each( arr, function(i, n){
// alert(i + ": " + n );
});
//遍历单个对象,回调函数第一个参数是键,第二个参数是值
var obj={ name: "John", lang: "JS" };
$.each(obj, function(index, n) {
//alert( index+"---" + n);
});
//遍历对象数组,回调函数第一个参数是数组下标,第二个参数是单个对象
var obj=[{ name: "a", age: 11 },{ name: "b", age: 12}];
$.each(obj, function(index, n) {
//alert( index+"---" + n.name+": "+n.age);
});
})
<p>段落1</p>
<div>div1</div>
<div>div2</div>
$(function() {
//去除空格
var string=" d ";
//alert(string.trim().length);
//alert($.trim(string).length);
//this在each中是dom对象
//回调函数不加参数,使用this
$("p").each(function() {
$(this).click(function() {
alert($(this).html());
});
});
//遍历一组dom元素:第一个为对象的成员或数组的索引,第二个为对应变量或内容
$("div").each(function(index, obj) {
//alert(index+"----"+$(obj).text());
});
//遍历数组,回调函数第一个参数是下标,第二个参数是数组元素
var arr=[0,1,2];
$.each( arr, function(i, n){
// alert(i + ": " + n );
});
//遍历单个对象,回调函数第一个参数是键,第二个参数是值
var obj={ name: "John", lang: "JS" };
$.each(obj, function(index, n) {
//alert( index+"---" + n);
});
//遍历对象数组,回调函数第一个参数是数组下标,第二个参数是单个对象
var obj=[{ name: "a", age: 11 },{ name: "b", age: 12}];
$.each(obj, function(index, n) {
//alert( index+"---" + n.name+": "+n.age);
});
})
阅读全文
0 0
- jQuery.each()与each()
- JQuery遍历-$.each()||$().each()
- JQUERY Each
- jquery each
- JQUERY/EACH()
- jquery each
- jQuery(each())
- jquery each()
- jquery each
- jquery each
- jQuery.each
- jQuery each()
- jquery each()
- jquery的$().each,$.each区别
- JQuery的$().each和$.each
- jquery的$().each,$.each区别
- jQuery $.each用法 与$().each
- jQuery 中的 each() 与 $.each()
- forIN 和 forOf
- jquery each,grap遍历方法
- 整理:手机端弹出提示框,使用的bootstrap中的模态框(modal,弹出层),比kendo弹出效果好
- 淘淘商城项目:Day3
- pc兼容问题
- jquery each()
- C++/MFC创建多线程的三种方法(转载)
- iOS App 签名的原理
- Scala--Function1
- [微信小程序]单选框以及多选框实例代码附讲解
- Git基本操作
- 【vscode】使用vscode多源文件结合opencv编译调试 C/C++
- 获取微信openID 的步骤
- Linux下SVN搭建