【发布时间】:2016-01-27 04:55:48
【问题描述】:
我有以下代码:
if (document.querySelectorAll('[id$=":maindiv:usernametext::content"]')[0].value == null || document.querySelectorAll('[id$="maindiv:usernametext::content"]')[0].value.trim() == "") {
console.log("maindiv:usernametext::content IS EMPTY !!!);
}
在 IE 8 中,这个元素总是说值是空的,即使它不是。在浏览器 > IE 8 以及 Chrome 和 Firefox 中运行时,它可以工作。为什么每次都返回null。我在 IE 8 标准模式下运行。
更新
所以我只是 console.log(document.querySelectorAll('[id$=":maindiv:usernametext::content"]')[0].value) 并且它正在返回值,但是这种情况不起作用?所以看起来选择器正在获取值,但是这个 if 语句在它不应该执行的时候执行,因为有一个值?该字段只是一个文本字段。
【问题讨论】:
-
您确定
document.querySelectorAll('[id$=":maindiv:usernametext::content"]')正在返回任何元素吗? -
专业提示:
QSA()[0]===querySelector(); -
@RocketHazmat 它在所有其他浏览器中返回,除了 IE 8
-
IE8 仅部分支持 querySelector/querySelectorAll
-
@SterlingArcher 我的查询会被支持吗?
标签: javascript html internet-explorer internet-explorer-8 css-selectors