Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> jak pobierac z "getAttribute" pod firefox
michalr
post 6.04.2006, 09:16:56
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 27.03.2006

Ostrzeżenie: (0%)
-----


mam taki obiekt XMLDOC:

<main>
<a name="a1">
<b name="b1" />
<b name="b2" />
</a>
</main>


a w JS robie tak:
var y = XMLDOC.getElementsByTagName("a") ;

i tak:
alert(y[0].childNodes[0].getAttribute("name"));

IE zwraca "b1"
ale Firefox nic ,
prosze o pomoc..

Ten post edytował michalr 6.04.2006, 09:52:52
Go to the top of the page
+Quote Post
pawel_k
post 6.04.2006, 09:29:50
Post #2





Grupa: Zarejestrowani
Postów: 211
Pomógł: 3
Dołączył: 29.07.2005
Skąd: Szczebrzeszyn

Ostrzeżenie: (0%)
-----


w firefoxie masz bardzo przydatną rzecz, a mianowicie Narzędzia > Konsola JavaScript

włącz, uruchom stronę i zobacz jaki błąd wywala...
Go to the top of the page
+Quote Post
michalr
post 6.04.2006, 09:44:46
Post #3





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 27.03.2006

Ostrzeżenie: (0%)
-----


no wyswietla

y[0].childNodes[0].getAttribute("name") is not a function

ale dlaczego w takim razie pod IE dziala..?
Go to the top of the page
+Quote Post
revyag
post 6.04.2006, 10:40:35
Post #4





Grupa: Przyjaciele php.pl
Postów: 2 258
Pomógł: 16
Dołączył: 21.09.2004
Skąd: Kielce

Ostrzeżenie: (0%)
-----


Chodzi o to że odczytywane są też spacje między tagami smile.gif Dlatego w ff dostajesz undefined.
Żeby było ok zapisz to tak:
  1. <a name="a1"><b name="b1" /><b name="b2" /></a>


--------------------
-------------

------
Go to the top of the page
+Quote Post
michalr
post 6.04.2006, 11:05:41
Post #5





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 27.03.2006

Ostrzeżenie: (0%)
-----


tak tez nic nie wyswietla
Go to the top of the page
+Quote Post
revyag
post 6.04.2006, 11:34:21
Post #6





Grupa: Przyjaciele php.pl
Postów: 2 258
Pomógł: 16
Dołączył: 21.09.2004
Skąd: Kielce

Ostrzeżenie: (0%)
-----


plik xml.
  1. <?xml version="1.0" encoding="ISO-8859-2"?>
  2. <m>
  3.    <a name="a1"><b name="b1" /><b name="b2" /></a>
  4. </m>

obsługa w js:
Kod
<script type="text/javascript">
var xmlDoc;
function loadXML() {
    if (window.ActiveXObject)  {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async=false;
        xmlDoc.load("note.xml");
        getmessage()
    } else if (document.implementation && document.implementation.createDocument) {
        xmlDoc=document.implementation.createDocument("","",null);
        xmlDoc.load("note.xml");
        xmlDoc.onload=getmessage
    } else {
        alert('Your browser cannot handle this script');
    }
}

function getmessage() {
    var y=xmlDoc.getElementsByTagName("a");
    alert(y[0].childNodes[0].getAttribute("name"));    
}

  1. <button onclick="loadXML()">show me</button>


pokazuje "b1"


--------------------
-------------

------
Go to the top of the page
+Quote Post
michalr
post 7.04.2006, 09:20:52
Post #7





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 27.03.2006

Ostrzeżenie: (0%)
-----


dzieki ,
okazalo sie ze poprostu w moim przypadku mialem te entery miedzy wierszami - po ich likwidacji dzialalo
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 27.04.2024 - 23:36