【问题标题】:HCL Notes 11 - Javascript - context.text not working in firefox but works in IEHCL Notes 11 - Javascript - context.text 在 Firefox 中不起作用,但在 IE 中起作用
【发布时间】:2021-11-11 09:18:11
【问题描述】:

以下代码在 IE 中有效,但在其他浏览器中无效。

var node = xmlHttp.responseXML.documentElement;
var eitems = node.getElementsByTagName("nib:ProcessRequestResponse");
txt = eitems.context.text;
txt2 = txt.replace("\n", "");

给出错误“eitems.context 未定义”。我也试过eitems.context.textContenteitems.context.innertexteitems.context.innerHTML。都给出相同的错误。

【问题讨论】:

    标签: javascript xmlhttprequest lotus-domino domino-designer-eclipse hcl-notes


    【解决方案1】:

    getElementsByTagName() 返回一个 HTMLCollection。使用

    访问第一个元素
     var item = eitems.item(0);
    

    或者只是

     var item = eitems[0];
    

    使用item获取内容。

    【讨论】:

    • eitems.item(0) 给出 null 而 eitems[0] 给出未定义。我需要标签“nib:ProcessRequestResponse”的完整内容。 eitems.length 在 IE 和其他浏览器中均显示为 0。但是 eitems.context.text 在 IE 中给出了标签的内容,而在其他浏览器中它给出了“未定义”。
    • getElementsByTagName() 返回什么?
    • node.getElementsByTagName("nib:ProcessRequestResponse") 返回 [object HTMLCollection]
    • console.log(JSON.stringify(Array.from(eitems))) 的输出是什么?
    【解决方案2】:

    我使用txt = node.textContent 来获取标签的内容并且它有效

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多