我有以下代码:
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 语句在它不应该执行的时候正在执行,因为有一个值?该字段只是一个文本字段。
最佳答案
原来 trim 不受 IE 8 支持,我删除了它并且它有效!
关于javascript - 元素在 IE 8 中始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33373753/