javascript - 在js jquery中获取孩子的src
问题描述
我需要比较 2 个元素,当它们是文本时,这是可行的:
if (first.children().text() != second.children().text())
但是,当它们是图像时,以下两个都不起作用,有什么想法吗?
if (first.children().getAttribute('src') != second.children().getAttribute('src'))
if (first.children().src() != second.children().src())
解决方案
getAttribute()
不是 jQuery 函数,它是可以在 DOM 元素上调用的原生 JS 函数。
您正在寻找 jQuery 的attr()
功能。
推荐阅读
- java - Maven deploy -x 给出 Failed to deploy artifacts ....拒绝访问:http://
- rx-java - 我想触发并忘记返回 Observable 的 HTTP 调用。我发现它阻塞了主线程
- mysql - Alter Query 比数据库中任何其他比它大的表花费更多的时间
- c++ - 查找重载与模板化函数时的不同 c++ 编译器行为
- c# - C#中参数的通配符
- android - Android 分配比垃圾收集快
- python - 按下按钮时更新 tkinter 矩形尺寸
- html - 如何停止进度条动画?
- python - Keras LSTM 不同的输入输出形状
- angular - 在Angular 2中单击时如何将输入值传递给另一个组件?