document.getElementByID外部还是内联? [英] document.getElementByID external or inline?

查看:130
本文介绍了document.getElementByID外部还是内联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 document.getElementByID 从外部JS文件中的HTML文件中提取信息,而且似乎不起作用。如果它与HTML文件是内联的或者可以在外部JS文件上正常工作,那么 document.getElementByID 是否有效?由于其他功能正常,JS文件正确地被调用。

解决方案


document.getElementByID只能与HTML文件一致使用


否。


可以在外部JS文件上正常工作吗?


是的。

在DOM准备就绪之前,您可能会调用 document.getElementById()


I have been trying to use the document.getElementByID to pull information from an HTML file from an external JS file and it does not seem to be working. Does the document.getElementByID only work if it is inline with the HTML file or can it work properly on an external JS file? The JS file is called upon within the HTML document properly because other functions are working.

解决方案

Does the document.getElementByID only work if it is inline with the HTML file

No.

can it work properly on an external JS file?

Yes.

You're probably calling document.getElementById() before the DOM is ready.

这篇关于document.getElementByID外部还是内联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆