简体   繁体   English

XSP.getElementById与document.getElementById

[英]XSP.getElementById vs document.getElementById

What is the difference between XSP.getElementById and document.getElementById ? XSP.getElementByIddocument.getElementById什么区别? In my tests both seem to return the same value (value stored in field). 在我的测试中,两者似乎都返回相同的值(存储在字段中的值)。 Which one should be preferred while coding for XPages? 为XPages编码时,应该首选哪一个?

edited 已编辑

XSP.getElementById is the same as dojo.byId which I believe works in wider range of browsers than document.getElementById . XSP.getElementByIddojo.byId相同,我相信它比document.getElementById可以在更广泛的浏览器中使用。

Here is the source for XSP.getElementById : 这是XSP.getElementById的来源:

   /**
    * Convenience function for retrieving an element given its id in a browser independent manner.
    */
    this.getElementById = function x_gbi(elementId){
        return dojo.byId(elementId);
    }

I guess for better future XPage support it might be a good idea to use XSP.getElementById (because they might change it) instead of dojo.byId . 我想获得更好的XPage未来支持,最好使用XSP.getElementById (因为它们可能会更改它)而不是dojo.byId I've been using dojo.byId because it's shorter. 我一直在使用dojo.byId因为它更短。 document.getElementById should never be used in XPages because we have dojo.byId . document.getElementById永远不要在XPages中使用,因为我们有dojo.byId

update 更新

Starting from Dojo 1.7 the syntax is much more complex: 从Dojo 1.7开始,语法更加复杂:

require(["dojo/dom"], function(dom){
    // fetch a node by id="someNode"
    var node = dom.byId("someNode");
});

Today my colleque pointed out that Dojo 2 will not support the current simple way of calling dojo.byId any more. 今天,我的同事指出, Dojo 2将不再支持当前调用dojo.byId简单方法。 This means that XSP.getElementById is definitely the way to go and we should start using the new require based syntax whenever we use Dojo with ND9. 这意味着XSP.getElementById绝对是必经之路,每当我们将ND9与Dojo一起使用时,就应该开始使用基于新的require语法。

XSP contains code for handling situations with the Notes client (XPiNC) and the web browser. XSP包含用于使用Notes客户端(XPiNC)和Web浏览器处理情况的代码。 Not using XSP calls in XPiNC may work or may have side effects. 在XPiNC中不使用XSP调用可能会起作用或有副作用。

XSP.getElementById works the same way as document.getElementById except it ensures that it works across browsers with the same functionality. XSP.getElementById的工作方式与document.getElementById相同,不同之处在于,它确保跨功能相同的浏览器工作。

You can read more about how XSP works in the "XPages Portable Command Guide" Page 184 for getElementById. 您可以在《 XPages可移植命令指南》第184页的getElementById上阅读有关XSP工作原理的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM