为什么$('.classname')只返回一个元素,当它是javascript等效document.getElementsByClassname('classname')返回一个元素数组?如果它不是彼此的等价物,那么它是什么?如何使用jQuery获取具有相同类名的所有元素?除了$('.classname')之外还有其他方法吗?例如,
1 2 3 4 5 如果我使用document.getElementsByClassName('currentMonth'),那么我将获得上面提到的所有元素的数组.
[1 ,2 ,3 ,4 ,5 ]但是
$('.currentMonth')
,我只能看到一个元素.如何使用所有元素
$
?
1> Praveen Kuma..:该
$('.currentMonth')
返回所有匹配的元素的jQuery对象.它以jQuery方式包装,但它也返回所有元素.您可以使用以下方法获取元素:$('.currentMonth').each(function () { this; // Here this refers to each of the matched element. });而
document.getElementsByClassname('currentMonth')
返回DOM对象列表.例如,如果我正在执行这样的脚本:
$('.currentMonth').html("Hello!");所有
s都将被更改. 推荐阅读
如何解决《域对象,工厂和存储库之间的依赖关系》经验,为你挑选了1个好方法。 ... [详细] 如何解决《检查是否在芹菜任务》经验,为你挑选了1个好方法。 ... [详细] 如何解决《C++:基类中的String参数在派生类解构时解构》经验,为你挑选了1个好方法。 ... [详细] 如何解决《在Maven中替换文件的正确方法是什么?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《如何在OCaml中创建大量线程?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《我可以将谷歌博客网站嵌入我的网站》经验,为你挑选了1个好方法。 ... [详细] 如何解决《检测未初始化对象的类型》经验,为你挑选了1个好方法。 ... [详细] 如何解决《当gulp为应用程序提供服务时,如何在webstorm中调试Javascript》经验,为你挑选了0个好方法。 ... [详细] 如何解决《从Android的LocationManager请求getLastKnownLocation时为空指针》经验,为你挑选了0个好方法。 ... [详细] 如何解决《测试列表中所有成员之间的相等性》经验,为你挑选了1个好方法。 ... [详细] 如何解决《logback没有找到maven的属性project.build.directory》经验,为你挑选了1个好方法。 ... [详细] 如何解决《x*log(x)与x^a有一个渐近极限,其中a是(1,2)?》经验,为你挑选了1个好方法。 ... [详细] 如何解决《Lua脚本从RedisHGETALL调用返回高效字典》经验,为你挑选了1个好方法。 ... [详细] 如何解决《HTML表单:POST一个对象数组》经验,为你挑选了2个好方法。 ... [详细] 如何解决《用Observable和Immutable改变检测》经验,为你挑选了2个好方法。 ... [详细] 如何解决《多线程环境中的基准标记》经验,为你挑选了1个好方法。 ... [详细] 如何解决《Excel到宏小数分隔符的剪贴板》经验,为你挑选了0个好方法。 ... [详细] 如何解决《使用唯一索引索引列表》经验,为你挑选了4个好方法。 ... [详细] 吐了个 "CAO" !Tags | 热门标签RankList | 热门文章
- 1单元测试Spring Cloud Service的策略
- 2密码管理:html中的硬编码密码
- 3在Eclipse中从MongoDB禁用控制台日志记录
- 4特定角色的strsplit,证明该角色不应该被特定角色所遵循
- 5Bootstrap模态动态宽度
- 6Android WebView键盘在android中隐藏片段中的输入字段
- 7django每周每月一次的方式对查询元素进行排序
- 8针对多个Java版本进行测试的最佳方法
- 9可以在C++中使用C标准库中的函数吗?
- 10按R中csv中的值选择行,并将它们保存在新的csv文件中
- 11如何在单元测试时测试绑定函数的相等性?
- 12Laravel 5.1更新数据透视表列而不删除现有记录
- 13如何在php中获取特定的数组值
- 14SQL min函数
- 15内容和标题不会显示在Wordpress的某些页面上
- 16如何在drawableLeft中设置图像的宽度和高度
- 17如何在c#.net中将结构转换为Byte数组,但仅在运行时定义结构大小
- 18如何从ajax php函数提醒框
- 19与Vuejs的Moment.js
- 20EF + AutoFac + async"连接的当前状态正在连接"
DevBox开发工具箱 | 专业的在线开发工具网站 京公网安备 11010802040832号 | 京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有