Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Java [игнор отключен] [закрыт для гостей] / Удаление фрагмента кода / 1 сообщений из 1, страница 1 из 1
07.08.2005, 11:31
    #33205490
Stalcer
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Удаление фрагмента кода
Помогите удалить код такого вида:

Код: plaintext
<b>text</b>text<a style='color:blue;' href='somelink'>text<img border= 0  src='images/image.gif'></a>

Пример удаления кода в приделах элемента <b>:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
<html>
    <head>
        <title>AbR</title>
        <script>
        function remove(tag,search)
        {
             if  (!tag || !search)  return  false;
            
            var elems = document.getElementsByTagName(tag);
                      
             if  (elems.length)
            {
                 for  (i =  0 , imax = elems.length; i < imax; i++)
                {
                     if  (!document.body) elems.item(i).normalize();
                     else 
                    {
                         for  (x =  0 , xmax = elems.item(i).childNodes.length; x < xmax; x++)
                        {
                             if  (elems.item(i).childNodes.item(x).nodeType ==  3 )
                            {
                                 if  (elems.item(i).childNodes.item(x).previousSibling && elems.item(i).childNodes.item(x).previousSibling.nodeType ==  3 )
                                {
                                    elems.item(i).childNodes.item(x).previousSibling.nodeValue += elems.item(i).childNodes.item(x).nodeValue;
                                    elems.item(i).childNodes.item(x).parentNode.removeChild(elems.item(i).childNodes.item(x));
                                }
                            }
                        }
                    }

                     for  (x =  0 , xmax = elems.item(i).childNodes.length; x < xmax; x++)
                    {
                         if  (elems.item(i).childNodes.item(x).nodeType ==  3 )
                        {
                            alert(elems.item(i).childNodes.item(x).nodeValue);
                             if  (elems.item(i).childNodes.item(x).nodeValue == search)
                            {
                                elems.item(i).parentNode.removeChild(elems.item(i));
                            }
                        }
                    }
                }
            }
        }    
        </script>
    </head>
    <body>
        <input type="button" value="Remove" onclick="remove('b','slmclmsc sl lsc lsjcjscj');">
        <b id="a">slmclmsc sl lsc </b>
    </body>
    <script>
        document.getElementById('a').appendChild(document.createTextNode('lsjcjscj'));
        </script>
</html>
...
Рейтинг: 0 / 0
Форумы / Java [игнор отключен] [закрыт для гостей] / Удаление фрагмента кода / 1 сообщений из 1, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]