좋아, 바보 같은 느낌이 드는 데, 여기에 문제가 정확히 무엇인지 궁금합니다.JS : 개체로 변환 할 수 없습니다. childNodes 관련
필자는 기능이 제대로 작동하지만 Opera에서 JS 오류가 발생합니다.
oElement = document.getElementById("shoutbox_area" + moduleId).childNodes;
function appendShout(XMLDoc)
{
var shoutData = XMLDoc.getElementsByTagName("item");
var oElement = [];
if (shoutData.length > 0)
{
var moduleId = shoutData[0].getAttribute("moduleid");
if (shoutData[shoutData.length - 1].getAttribute("lastshout") != "undefined")
{
for (var i = 0; i < shoutData.length; i++)
if (shoutData[i].firstChild.nodeValue != 0)
document.getElementById("shoutbox_area" + moduleId).innerHTML += shoutData[i].firstChild.nodeValue;
oElement = document.getElementById("shoutbox_area" + moduleId).childNodes;
var i = oElement.length;
while (i--)
{
if (i % 2 == 0)
oElement[i].className = "windowbg2";
else
oElement[i].className = "windowbg";
}
oElement[oElement.length - 2].style.borderBottom = "1px black dashed";
}
}
}
누군가가 나에게 여기 오류를주고있다 이유를 이해하는 데 도움 주실 래요 : 여기
는 관련 코드입니다 ... 다른 브라우저에 대한 확실하지 않음Uncaught exception: TypeError: Cannot convert 'document.getElementById("shoutbox_area" + moduleId)' to object oElement = document.getElementById("shoutbox_area" + moduleId).childNodes;
배열을 childNodes에 할당 할 수 없습니까?
편집 :
이 JS 오류는 외침을 시도하거나 삭제할 때 발생합니다. 외침을 삭제하는 JS 기능은 이것이다 :
function removeShout(shout, moduleID)
{
var shoutContainer = shout.parentNode.parentNode;
var send_data = "id_shout=" + shout.id;
var url = smf_prepareScriptUrl(smf_scripturl) + "action=dream;sa=shoutbox;xml;" + "delete_shout;" + "canmod=" + canMod[moduleID] + ";" + sessVar + "=" + sessId;
sendXMLDocument(url, send_data);
var shoutID = 0;
while (shoutID !== null)
{
var shoutID = document.getElementById(shout.parentNode.id);
var moduleID = shoutID.parentNode.getAttribute("moduleid");
if (shoutID.parentNode.lastChild)
{
var url = smf_prepareScriptUrl(smf_scripturl) + "action=dream;sa=shoutbox;xml;get_shouts=" + (shoutID.parentNode.lastChild.id.replace("shout_", "") - 1) + ";membercolor=" + memberColor[moduleID] + ";maxcount=" + maxCount[moduleID] + ";shoutboxid=" + shoutboxID[moduleID] + ";textsize=" + textSize[moduleID] + ";parsebbc=" + parseBBC[moduleID] + ";moduleid=" + moduleID + ";maxcount=" + maxCount[moduleID] + ";canmod=" + canMod[moduleID] + ";" + sessVar + "=" + sessId;
getXMLDocument(url, appendShout);
}
element = shoutID.parentNode.childNodes;
var i = element.length;
while (i--)
{
if (i % 2 == 0)
element[i].className = "windowbg2";
else
element[i].className = "windowbg";
}
shoutID.parentNode.removeChild(shoutID);
}
}
위의 removeShout 기능을 이미 눈치 챘을 수도로 보내고는 XMLHttpRequest를 얻기 위해 다음과 같은 기능을 사용하고 있습니까 : 희망이
// Load an XML document using XMLHttpRequest.
function getXMLDocument(sUrl, funcCallback)
{
if (!window.XMLHttpRequest)
return null;
var oMyDoc = new XMLHttpRequest();
var bAsync = typeof(funcCallback) != 'undefined';
var oCaller = this;
if (bAsync)
{
oMyDoc.onreadystatechange = function() {
if (oMyDoc.readyState != 4)
return;
if (oMyDoc.responseXML != null && oMyDoc.status == 200)
{
if (funcCallback.call)
{
funcCallback.call(oCaller, oMyDoc.responseXML);
}
// A primitive substitute for the call method to support IE 5.0.
else
{
oCaller.tmpMethod = funcCallback;
oCaller.tmpMethod(oMyDoc.responseXML);
delete oCaller.tmpMethod;
}
}
};
}
oMyDoc.open('GET', sUrl, bAsync);
oMyDoc.send(null);
return oMyDoc;
}
// Send a post form to the server using XMLHttpRequest.
function sendXMLDocument(sUrl, sContent, funcCallback)
{
if (!window.XMLHttpRequest)
return false;
var oSendDoc = new window.XMLHttpRequest();
var oCaller = this;
if (typeof(funcCallback) != 'undefined')
{
oSendDoc.onreadystatechange = function() {
if (oSendDoc.readyState != 4)
return;
if (oSendDoc.responseXML != null && oSendDoc.status == 200)
funcCallback.call(oCaller, oSendDoc.responseXML);
else
funcCallback.call(oCaller, false);
};
}
oSendDoc.open('POST', sUrl, true);
if ('setRequestHeader' in oSendDoc)
oSendDoc.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
oSendDoc.send(sContent);
return true;
}
실제 HTML을보기 위해 뷰 소스를 수행 할 수 있지만 XHTML과 호환되도록 런타임시 Shoutbox 태그에 추가되는 속성이 있습니다.
네가 필요로 하는게있어?
감사합니다 :)
무엇이'moduleId'입니까? 타겟팅하는 요소의 ID는 무엇입니까? 어떤 childNodes에 포함되어 있습니까? HTML이 유용 할 것입니다. –
질문을 수정했습니다. 바라기를 이것은 나에게 도움이 될만한 충분한 정보입니다. 니가 필요로하는 것이 있으면 알려줘. 고마워요. 도와 주셔서 대단히 감사합니다! :) – SoLoGHoST