javascript getelementbyid 为空
这很奇怪,过去两天我一直在用头撞墙。以前做过类似的事情,所以不确定问题是什么。
您可以在此处查看工作页面: http://psssoftware.net/forms.html
我试图隐藏右侧的“testbox”,但是当我尝试通过 id 获取它时,那里什么也没有。没有其他元素具有相同的标签名称,id 是正确的。一定有什么东西我错过了,希望另一双眼睛能看到。
<script language="JavaScript" type="text/javascript">
var x = document.getElementById('col-ab-affUSLF');
var y = document.getElementById('col-c-affUSLF');
x.style.width = 'auto !important';
y.style.display = 'none !important';
</script>
谢谢, 布莱克
This is a strange one Ive been banging my head against a wall for the past 2 days. Have done something similar before so not sure what the issue is.
You can see working page here: http://psssoftware.net/forms.html
I am trying to hide the "testbox" on the right but when I try to get it by id there is nothing there. There are no other elements with the same tag name, the id is correct. There has to be something I am missing hopefully another pair of eyes will see.
<script language="JavaScript" type="text/javascript">
var x = document.getElementById('col-ab-affUSLF');
var y = document.getElementById('col-c-affUSLF');
x.style.width = 'auto !important';
y.style.display = 'none !important';
</script>
Thanks,
Blake
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
调用 getElementById 时,具有给定 ID 的元素不存在。 [许多]框架在进行 DOM 操作(包括尝试获取具有给定 ID 的元素)之前“等待 DOM 准备就绪”(例如 onload)是有原因的。
快乐编码。
The element with the given ID does not exist at the time getElementById was called. There is a reason why [a number of] frameworks "wait for DOM ready" (e.g. onload) before doing DOM manipulation (including trying to get an element with a given ID).
Happy coding.
此行中有一个不需要的双引号:
看起来它正在丢弃您的脚本标记。
You have an unneeded double quote in this line:
It looks like it's throwing off your script tag.
查看源代码,这是您的js:
看起来您的
y.style.display = 'none !important"';
中有一个额外的 双引号 "Looking in the source, this is your js:
It looks like you have a extra double quote " in your
y.style.display = 'none !important"';