访问 DOM 时发生 JavaScript 冲突
我从我读过的书中读到了这个声明
文档对象模型或 DOM 实际上不是 JavaScript 的一部分,而是存在于 JavaScript 之外的独立实体。尽管您可以使用 JavaScript 来操作 DOM 对象,但其他脚本语言也可以同样很好地访问它们。
当我们必须处理 XMLHTTPRequest 对象时,避免 javascript 和其他客户端脚本语言之间冲突的最佳方法是什么
i read this statement from a book i read
The Document Object Model or DOM is really not a part of JavaScript but a separate entity existing outside it. Although you can use JavaScript to manipulate DOM objects, other scripting languages may equally well access them too.
what is the best way to avoid conflict between javascript and other client-siede scripting language when we have to deal with XMLHTTPRequest object
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无需担心其他重要的客户端脚本语言。其他一些可能会修改普通网页上 DOM 的东西是如此晦涩难懂,如果您使用它们,您就会知道。您可以假设您拥有对 DOM 的独占访问权限。
There are no other significant client-side scripting languages you'd need to worry about. The few other things that might modify the DOM on a normal web page are so obscure you'd know if you were using them. You can assume you have exclusive access to the DOM.
如果您无法确定同一页面上还有哪些其他脚本可以操作相同的 DOM,那么如果它们是用不同的语言编写的,那么这可能并不重要。那么问题是,还有其他脚本——无论是否是JavaScript。
我会使用具有唯一名称的顶级对象,并将我的所有内容放在该对象下。这样,名称冲突的可能性就较小。
If you can't be sure about which other scripts there are on the same page, that could manipulate the same DOM, then it probably doesn't matter, if they're written in a different language. The problem is then, that there are other scripts - JavaScript or not.
I'd use a top level object with a unique name, and put all my things under that object. This way, name conflicts are less likely.
这种情况并不常见。
您的网站上是否使用任何其他客户端语言?如果您没有运行任何 flash、silverlight、ActiveX 等,则无需担心。
即使您是这样,也只需确保他们没有操作 DOM 的同一部分 - 无论如何您可能都会这样做。
This is not a common occurrence.
Are you using any other client-side languages on your site? If you do not have any flash, silverlight, ActiveX, etc running around then there is nothing to worry about.
And even if you are, just make sure they are not manipulating the same section of the DOM - which you would probably be doing anyway.