Удаление узла

Тема в разделе "HTML, CSS, XML, JavaScript", создана пользователем Remka, 21 янв 2009.

  1. Remka

    Remka Гость

    Всем привет, у меня имеется документ, в котором надо удалить фрагмент кода. Союственно я написал код на javascript.
    [codebox]<script language="Javascript">
    7 function test(){
    8 var docBody=document.getElementsByTagName('body').item(0);
    9 var allSpan=document.getElementsByTagName('span');
    10 var SrchStr='...';
    11 for (var i=0;i<allSpan.length;i++){
    12 if ((allSpan.item(i).textContent)==(SrchStr)){
    13 var DelTxt=allSpan.item(i);
    14 alert(DelTxt.innerHTML);
    15 removed=docBody.removeChild(DelTxt);
    16 }
    17 }
    18 return false;
    19}
    20</script>
    21<input type=submit onclick="test()" value= 'GO copy' >[/codebox]
    Но он не работает, FF возращает что нет такого узла. (uncaught exception: Node was not found (NS_ERROR_DOM_NOT_FOUND_ERR)
    [Break on this error] removed=docBody.removeChild(DelTxt); )
    Вот анализируем фрагмент кода:
    [codebox]<html>
    <head>
    <title>qwe</title>
    </head>
    <body>
    <script language="Javascript">
    function test(){
    var docBody=document.getElementsByTagName('body').item(0);
    var allSpan=document.getElementsByTagName('span');
    var SrchStr='...';
    for (var i=0;i<allSpan.length;i++){
    if ((allSpan.item(i).textContent)==(SrchStr)){
    var DelTxt=allSpan.item(i);
    alert(DelTxt.innerHTML);
    removed=docBody.removeChild(DelTxt);
    }
    }
    return false;
    }
    </script>
    <input type=submit onclick="test()" value= 'GO copy' >
    <form action="#" name=bbb>
    <table border="1">
    <tr><td>+00</td><td><input type="checkbox" name="g1" id="g1" ></td></tr>
    <tr><td>+11</td><td><input type="checkbox" name="g2" id="g2" ></td></tr>
    <tr><td>+01</td><td><input type="checkbox" name="g3" id="g3" ></td></tr>
    <tr><td>+10</td><td><input type="checkbox" name="g4" id="g4" ></td></tr>
    <tr><td> Имя:<td/><td><input type="text" value="<Enter Text>" id="t1"></td></tr>
    <tr><td><input type="button" value="EDIT" onClick=""></td></tr>
    </table>
    </form>
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    lendar/calendar.gif" width="20px" height="20px" align="top" border="0" style="position:relative" id="idGFPMultiSelectsaw_77_5BetweenA"></a> <b>and</b> 
    <input type="text" maxLength="12" size="9" name="BetweenB"><a onclick="saw.stopEventPropagation(event); NQCShowCalendar(document.getElementById('idGFPMultiSelectsaw_77_5BetweenB'),document.forms['idGFPMultiSelectsaw_77_5SearchForm'].BetweenB,document.forms['idGFPMultiSelectsaw_77_5SearchForm'].BetweenB,null,false,null,nqcalmns,nqdfmt,nqdsep);return false" href="java script:void(null)"><img src="res/sk_oracle10/calendar/calendar.gif" width="20px" height="20px" align="top" border="0" style="position:relative" id="idGFPMultiSelectsaw_77_5BetweenB"></a></td><td class="MultiSelectButtonCell"><span class="minibuttonOn"><a title="Go" onclick="GFPMultiSelect.Go('idGFPMultiSelectsaw_77_5'); return false;" href="java script:void(null)">Go</a></span></td></tr></table><table id="idGFPMultiSelectsaw_77_5NumericTable" class="XUIPromptTable" cellspacing="0"><tr><td class="XUIPromptCaption"><b>Values Between:</b></td><td class="XUIPromptEntry"><input type="text" size="7" name="BetweenNA"> <b>and</b> 
    <input type="text" size="7" name="BetweenNB"></td><td class="MultiSelectButtonCell"><span class="minibuttonOn"><a title="Go" onclick="GFPMultiSelect.Go('idGFPMultiSelectsaw_77_5'); return false;" href="java script:void(null)">Go</a></span></td></tr></table></form></td></tr><tr><td><div id="idGFPMultiSelectsaw_77_5Selections" class="ValueList" style="width:200px; height:150px" onclick="return GFPMultiSelect.ClickSelection(event, 'idGFPMultiSelectsaw_77_5', false)" ondblclick="return GFPMultiSelect.DoubleClickSelection(event, 'idGFPMultiSelectsaw_77_5', false)"></div></td><td><table><tr><td class="ShuttleButtons"><span class="minibuttonOn"><a id="idGFPMultiSelectsaw_77_5SelectAll" title="Move All" onclick="GFPMultiSelect.SelectAll('idGFPMultiSelectsaw_77_5', true); return false;" href="java script:void(null)"><<</a></span><p></p><span class="minibuttonOn"><a id="idGFPMultiSelectsaw_77_5Select" title="Move" onclick="GFPMultiSelect.Select('idGFPMultiSelectsaw_77_5', true); return false;" href="java script:void(null)"> < </a></span><p></p><span class="minibuttonOn"><a id="idGFPMultiSelectsaw_77_5Deselect" title="Remove" onclick="GFPMultiSelect.Select('idGFPMultiSelectsaw_77_5', false); return false;" href="java script:void(null)"> > </a></span><p></p><span class="minibuttonOn"><a id="idGFPMultiSelectsaw_77_5DeselectAll" title="Remove All" onclick="GFPMultiSelect.SelectAll('idGFPMultiSelectsaw_77_5', false); return false;" href="java script:void(null)">>></a></span></td></tr></table></td><td style="text-align:center"><div id="idGFPMultiSelectsaw_77_5Choices" class="ValueList" style="height:150px;text-align:left" onclick="return GFPMultiSelect.ClickSelection(event, 'idGFPMultiSelectsaw_77_5', true)" ondblclick="return GFPMultiSelect.DoubleClickSelection(event, 'idGFPMultiSelectsaw_77_5', true)"></div></td></tr><tr><td class="MultiSelectButtonCell"><span class="minibuttonOn"><a title="Edit" onclick="GFPMultiSelect.Edit(event, 'idGFPMultiSelectsaw_77_5'); return false;" href="java script:void(null)">Edit</a></span></td><td></td><td class="XUIPromptCaption"><table><tr><td><b>Choices Returned: </b></td><td id="idGFPMultiSelectsaw_77_5Total"></td><td class="MultiSelectButtonCell"><span class="minibuttonOn"><a id="idGFPMultiSelectsaw_77_5More" title="More..." onclick="void(null); return false;" href="java script:void(null)">More...</a></span></td></tr></table></td></tr></table></td></tr><tr class="XUIPromptToolbar"><td class="XUIDialogButtonsCell" style="text-align: left"></td><td style="text-align: right"><div align="right"><table><tr>
    <td class="XUIDialogButtonsCell"><span class="minibuttonOn" id="idGFPMultiSelectsaw_77_5OKButton"><a id="idGFPMultiSelectsaw_77_5xuidialogok" onclick="return XUIDialog.ok('idGFPMultiSelectsaw_77_5', event)" href="java script:void(null)">OK</a></span></td><td class="XUIDialogButtonsCell"><span class="minibuttonOn"><a id="idGFPMultiSelectsaw_77_5xuidialogcancel" onclick="return XUIDialog.cancel('idGFPMultiSelectsaw_77_5')" href="java script:void(null)">Cancel</a></span></td></tr></table></div></td></tr></table>
    </td>
    <td class="shadowOffsetCellRight"></td></tr>
    <tr><td class="shadowRight"> </td></tr><tr><td class="shadowOffsetCellBottom"></td><td class="shadowBottom"> </td><td class="shadowCorner"></td></tr></table></div>
    <div id="idGFPMultiSelectEditDiv" class="dialogDiv" style="position:absolute;display:none;" captureKey="">
    <table cellspacing="0px" >
    <tr><td rowspan="2" colspan="2" class="shadowDialogCell"><table class="XUIDialogTable" cellspacing="0px"><tr class="XUIDialogTitleBar" id="titleBar" onMouseover="setHot('idGFPMultiSelectEditDiv');" onMouseout="setCold();"><td class="XUIDialogTitleCell"><span onSelectStart="return false;">Edit</span></td><td class="XUIDialogHelpCell" style="text-align: right"></td></tr><tr><td class="XUIDialogEditorCell" colspan="2"><textarea cols="40" rows="7" id="idGFPMultiSelectEditArea" class="EditTextArea"></textarea></td></tr><tr class="XUIPromptToolbar"><td class="XUIDialogButtonsCell" style="text-align: left"></td><td style="text-align: right"><div align="right"><table><tr>
    <td class="XUIDialogButtonsCell"><span class="minibuttonOn" id="idGFPMultiSelectEditOKButton"><a id="idGFPMultiSelectEditxuidialogok" onclick="return XUIDialog.ok('idGFPMultiSelectEdit', event)" href="java script:void(null)">OK</a></span></td><td class="XUIDialogButtonsCell"><span class="minibuttonOn"><a id="idGFPMultiSelectEditxuidialogcancel" onclick="return XUIDialog.cancel('idGFPMultiSelectEdit')" href="java script:void(null)">Cancel</a></span></td></tr></table></div></td></tr></table>
    </td>
    <td class="shadowOffsetCellRight"></td></tr>
    <tr><td class="shadowRight"> </td></tr><tr><td class="shadowOffsetCellBottom"></td><td class="shadowBottom"> </td><td class="shadowCorner"></td></tr></table></div><form action="java script:void(null);" name="d:dashboard~p:4ne48shhbjbvoo6c~s:m8fbia2fucgidagu~g:2b2sjpl05a51bvaaform" id="d:dashboard~p:4ne48shhbjbvoo6c~s:m8fbia2fucgidagu~g:2b2sjpl05a51bvaaform" method="post" style="margin: 0;">
    <table class="GFPBox" id="saw_77_5" cellspacing=0>
    <tr>
    <td><a href="java script:void(null)" onclick="IgnoreEvent();" title="Dashboard Prompt" name="SectionElements"></a><table class="GFPPromptTable" border=0 cellspacing=0>
    <tr>
    <td class="GFPFilter" GFPBuilder="{ GFPBuildFilter('Markets.Region','in','multi','0','',GFPHandleEmptyInput(document.getElementById('saw_77_6').value, document.getElementById('saw_77_6').getAttribute('emptyAsAllChoices'))); }" sID="saw_77_6">
    <Span class="GFPCaption" style="">RegionX</Span><BR><Span class="GFPControl" style=""><input type="text" id="saw_77_6" name="saw_77_6" size="10" onchange="" value="" emptyAsAllChoices="false" disabled> <span class="minibuttonOn"><a href="java script:void(null)" onclick="return GFPDoMultiSelect(event, 'saw_77_6','Markets.Region','Paint','','saw_77_5','text','text','', '')">...</a></span></Span></td></tr>
    </table>
    </td>
    <td class="GFPSubmit"><table cellspacing=0>
    <tr>
    <td class="XUIPromptEntry"><span class="minibuttonOn"><a href="java script:void(null)" onclick="java script:GFPDoFilters('d:dashboard~p:4ne48shhbjbvoo6c~s:m8fbia2fucgidagu~g:2b2sjpl05a51bvaa',document.getElementById('saw_77_5'),true);return false;">Go</a></span><div id="d:dashboard~p:4ne48shhbjbvoo6c~s:m8fbia2fucgidagu~g:2b2sjpl05a51bvaaScope" value="dashboard"/></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form></td>
    </tr>
    </table>
    </div></div>
    </div>
    </td>
    </tr></table>
    </td></tr>
    </table>
    </div>
    </td></tr></table>
    </td><td class="PageColumnCell" valign="top" style="" ><table class="ColumnTable" cellspacing=0><script language="javascript">if (saw.dashboard) saw.dashboard.addReportId('d:dashboard~p:4ne48shhbjbvoo6c~s:r1kmb264glc3ti45');</script><tr><td >
    <div id="Embedd:dashboard~p:4ne48shhbjbvoo6c~s:r1kmb264glc3ti45" minimized="false" rendered="false">
    <a name="SectionTableTitle" href="java script:void(null)" title="Section "></a>
    <table class="SectionTable" cellspacing=0 style="" >
    <tr>
    <td>
    <table id="d:dashboard~p:4ne48shhbjbvoo6c~s:r1kmb264glc3ti45Contents" style="width:100%;">
    </body>
    </html>
    [/codebox]
    Заранее всем СПС! Javascript я пока что 3 день изучаю, так что плохо в нем разбираюсь(

    <span class="minibuttonOn"><a href="java script:void(null)" onclick="return GFPDoMultiSelect(event, 'saw_77_6','Markets.Region','Paint','','saw_77_5','text','text','', '')">...</a></span></
    Вот строка, которую надо удалить.
     
  2. Vovochka

    Vovochka Гость

    Не docBody.removeChild, а span.parent.removeChild(span);
     
  3. Remka

    Remka Гость

Загрузка...

Поделиться этой страницей