JS/jQuery 遍历对象属性
2016-09-02 10:57
447 查看
Javascript For/In 循环: 循环遍历对象的属性
[javascript]
view plain
copy
var person={fname:"John",lname:"Doe",age:25};
for (x in person)
{
txt=txt + person[x];
}
结果:JohnDoe25
也可以
jQuery jQuery.each() 遍历对象属性
[javascript]
view plain
copy
var arr = ["one", "two", "three", "four", "five"];
var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 };
遍历数组
[javascript]
view plain
copy
var text = "Array ";
jQuery.each(arr, function(i, val) {
text = text + " #Index:" + i + ":" + val;
});
console.log(text);
//Array #Index:0:one #Index:1:two #Index:2:three #Index:3:four #Index:4:five
d9d4
遍历对象
[javascript]
view plain
copy
text = "Object ";
jQuery.each(obj, function(i, val) {
text = text + "Key:" + i + ", Value:" + val;
});
console.log(text);
//Object Key:one, Value:1Key:two, Value:2Key:three, Value:3Key:four, Value:4Key:five, Value:5
[javascript]
view plain
copy
var person={fname:"John",lname:"Doe",age:25};
for (x in person)
{
txt=txt + person[x];
}
结果:JohnDoe25
也可以
jQuery jQuery.each() 遍历对象属性
[javascript]
view plain
copy
var arr = ["one", "two", "three", "four", "five"];
var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 };
遍历数组
[javascript]
view plain
copy
var text = "Array ";
jQuery.each(arr, function(i, val) {
text = text + " #Index:" + i + ":" + val;
});
console.log(text);
//Array #Index:0:one #Index:1:two #Index:2:three #Index:3:four #Index:4:five
d9d4
遍历对象
[javascript]
view plain
copy
text = "Object ";
jQuery.each(obj, function(i, val) {
text = text + "Key:" + i + ", Value:" + val;
});
console.log(text);
//Object Key:one, Value:1Key:two, Value:2Key:three, Value:3Key:four, Value:4Key:five, Value:5
相关文章推荐
- jQuery序列化后的表单值转换成Json
- jQuery打印插件jqprint
- JQuery源码解析-定义变量和函数,赋值JQuery
- checkbox select jquery 回显
- 我的jQuery学习之路_笔记(五)
- 扩展jquery插件好jquery自身方法
- jquery 格式化日期显示
- JQuery源码解析-整体架构的设计
- 利用jquery做的滑动按钮开关
- 用户界面框架jQuery EasyUI示例大全之菜单和拆分按钮演示
- jquery超炫瀑布流相册插件特效代码--适合做个人博客相册
- jQuery LigerUI ligerTree展开指定节点
- 基于jQuery实现发送短信验证码后的倒计时功能(无视页面关闭)
- 初见jqm
- jQuery als.js 跑马灯
- 转载JQuery 获取设置值,添加元素详解
- 转载JQuery 中empty, remove 和 detach的区别
- jquery.form.js实现将form提交转为ajax方式提交的方法
- Jquery通过Ajax方式来提交Form表单
- 实现表单的提交通过jquery的ajax