gpt4 book ai didi

javascript - 将 [object HTMLCollection] 转换为 javascript 中的字符串

转载 作者:太空宇宙 更新时间:2023-11-04 13:55:47 25 4
gpt4 key购买 nike

我正在尝试使用通过 getElementByTagName 从 XML 文件中提取的数据,它返回 HTML Collection Object 但我需要这些数据来发送 REST 请求,所以我需要获取要转换为字符串的 HTML 集合对象。怎么做到的?

这里有更多信息:

com_zimbra_om.prototype._responseHandler=
function(response){
try{
sid = response.xml.getElementsByTagName("session_id");
this.login_user();
}catch(e){
this._showErrorMsg(e);
}

使用此函数,我试图从 REST 响应中获取 session_id。这里的 sid(全局变量)是 HTML 集合对象。现在,当我尝试在下一个函数中使用它时:

com_zimbra_om.prototype.login_user = function(){
var url = selected_server + 'services/UserService/loginUser?SID=' +
sid + '&username='+
selected_username +
'&userpass=' +
selected_password;
var request_url = ZmZimletBase.PROXY + AjxStringUtil.urlComponentEncode(url);

所以我在这里使用 sid 作为字符串。

那么我应该如何将 HTML Collection Object 转换成字符串呢?

谢谢

最佳答案

有了这些信息,我只能去

var objectHTMLCollection = document.getElementsByTagName("div"),
string = [].map.call( objectHTMLCollection, function(node){
return node.textContent || node.innerText || "";
}).join("");

关于javascript - 将 [object HTMLCollection] 转换为 javascript 中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11125825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com