JSNI中的$ doc.getElementById(“id”)和document.getElementById(“id”)之间的区别是什么 [英] Which is the difference between $doc.getElementById("id") and document.getElementById("id") in JSNI

查看:245
本文介绍了JSNI中的$ doc.getElementById(“id”)和document.getElementById(“id”)之间的区别是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个GWT应用程序中的本机功能,我已经尝试了这两个方法:document.getElementById(id)返回null但$ doc.getElementById()返回一个有效的元素。
这个方法有什么区别(概念上)?
提前感谢

解决方案

您的GWT应用程式的代码会在(隐藏)的iframe中运行,所以文档引用iframe的文档(和窗口 iframe的浏览上下文)。 GWT因此初始化变量 $ doc $ wnd ,让您轻松引用文档和浏览上下文(



请注意,连接人员决定如何加载已编译的代码,默认值为($) c $ c> std )和较新的 xsiframe 使用iframe,而不建议使用的 xs 在同一浏览环境中加载代码(所以 $ doc == document $ wnd == window


I'm working in a native function inside a GWT application and I've tried this two methods: document.getElementById("id") returns null but $doc.getElementById() returns a valid element. Which is the difference (conceptually) between this methods? Thanks in advance.

解决方案

The code of your GWT app runs in a (hidden) iframe, so document references that iframe's document (and window the iframe's browsing context). GWT thus initializes the variables $doc and $wnd to let you easily reference the document and browsing context (window) of the "host page" that loads the GWT app.

Note that linkers decide how the compiled code is loaded, the default one (std) and the newer xsiframe use iframes, whereas the deprecated xs loads your code in the same browsing context (so $doc == document and $wnd == window)

这篇关于JSNI中的$ doc.getElementById(“id”)和document.getElementById(“id”)之间的区别是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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