访问 .load() 函数中的 $(this) 元素
Access $(this) element inside .load() function
我正在尝试在加载图像后从图像中删除loader icon
。为此,我需要访问$(this)
但我无法访问图像元素并删除js-image-loading
类。
变量html
包含通过 AJAX 获取的动态HTML
内容。
$(html).find('img').load(function() {
$(this).removeClass("js-image-loading"); //ok image is done loading, remove icon
});
这可能做到吗?
你忘了引用应该$('html')
的html选择器$(html)
但我建议你使用*
:
$('*').find('img').load(function() {
$(this).removeClass("js-image-loading");
});
或者,干脆$('img').load()
试试
$("html").find('img').load(function () {
$(this).removeClass("js-image-loading"); //ok image is done loading, remove icon
});
或
$('img').load(function () {
$(this).removeClass("js-image-loading"); //ok image is done loading, remove icon
});
注意:html 是字符串而不是对象
演示
相关文章:
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- jQuery:具有class但不具有$(this)的元素
- this.defaultValue 返回 select 元素的未定义
- jQuery(this) 目標不是找到元素
- 如何通过 id 获取“this”元素并查看是否选中
- 同一元素的 this.id 值在浏览器之间是不同的
- 将jQuery$(this)转换为原始元素
- 如何在jQuery中隐藏没有$this的父元素
- jQuery不使用“$(this)”返回必需的元素
- 如何选择 $(this) 之后的下一个元素
- Jquery从“this”内部的元素制作变量
- 在 JavaScript / jQuery 回调中使用“this”更改单击元素的文本
- 从在javascript中共享类的THIS元素中获取值
- 将焦点放在由 ng-click 调用的函数中的“this”元素上
- 我如何定位“这个”?this' "元素的孩子
- 验证的重点是错误,AND引用THIS元素
- 在jQuery中,“this”和“this”的区别是什么?元素'和' this.元素[/*某数*/]'
- 将绑定函数包装到THIS元素
- 通过“this"元素到JS函数中使用"javascript:"URL
- 这是访问javascript对象的this元素的正确方法