2010-11-30 2 views
0

좋아, 바보 같은 느낌이 드는 데, 여기에 문제가 정확히 무엇인지 궁금합니다.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 태그에 추가되는 속성이 있습니다.

네가 필요로 하는게있어?

감사합니다 :)

+0

무엇이'moduleId'입니까? 타겟팅하는 요소의 ID는 무엇입니까? 어떤 childNodes에 포함되어 있습니까? HTML이 유용 할 것입니다. –

+0

질문을 수정했습니다. 바라기를 이것은 나에게 도움이 될만한 충분한 정보입니다. 니가 필요로하는 것이 있으면 알려줘. 고마워요. 도와 주셔서 대단히 감사합니다! :) – SoLoGHoST

답변

1

shoutID이 두 선 루프를 통해 두 번째의 두 번째의 null 때문에 코드가 파괴되어 그 라인의

var shoutID = document.getElementById(shout.parentNode.id); 
var moduleID = shoutID.parentNode.getAttribute("moduleid"); 

첫 번째는 이상하다. 왜 var shoutID = shout.parentNode;을 사용하지 않는 것이 좋을까요?
또한 moduleId 속성은 아무 곳에도없는 것으로 보입니다.

while 루프를 사용하여 달성하려는 목표는 무엇입니까?

+0

와우, 고마워. 나는 그 약간의 코드를 간과했다. 나는 실제로 한 번에 하나 이상의 외침이 제거되도록 고려하고있었습니다. 어쨌든, 그 루프를 제거하고 그것은 JS 오류 중 하나를 고정 것으로 보인다. 그러나'moduleid' 속성은 RUNTIME에 만들어 지므로 왜 이것이 문제인지 ...? 고맙습니다! – SoLoGHoST

+0

OMG, 당신은 굉장하고 나는 지쳤습니다! 이 함수에서 두 번째 매개 변수로 전달 된 moduleID가 있으므로이 모듈을 제거했습니다. var moduleID = shoutID.parentNode.getAttribute ("moduleid");'두 번째 매개 변수에서 올바른 moduleId 값을 가져옵니다. 이것에 관해 또 다른 눈으로 도와 줘서 고맙습니다. 때때로 나는 4 눈을 가지기를 바랍니다. 대단히 감사합니다! – SoLoGHoST

관련 문제