![]() |
![]() |
--void-- |
![]()
Post
#1
|
Goście ![]() |
Kod var pt=0; function getQuestions() { obj=document.getElementById("question"); obj.firstChild.nodeValue="(please wait)"; ajaxCallback = nextQuestion; ajaxRequest("questions.xml"); } function nextQuestion() { questions = ajaxreq.responseXML.getElementsByTagName("q"); obj=document.getElementById("question"); if (pt < questions.length) { q = questions[pt].firstChild.nodeValue; obj.firstChild.nodeValue=q; } else { obj.firstChild.nodeValue="(no more questions)"; } } Bardzo proszę o pomoc. Ten fragment skryptu nie działa, konkretnie nie pobiera danych z pliku questions.xml, który wygląda tak: Kod <?xml version="1.0" ?> <questions> <q>Pytanie</q> </a>Odpowiedź</a> </questions> (IMG:http://forum.php.pl/style_emoticons/default/blinksmiley.gif) Pozdrawiam. |
|
|
![]() |
--void-- |
![]()
Post
#2
|
Goście ![]() |
ehh, jeszcze quiz.js
Kod // zmienna globalna qn jest numerem bieżącego pytania
var qn=0; // wczytaj pytania z pliku XML function getQuestions() { obj=document.getElementById("question"); obj.firstChild.nodeValue="(please wait)"; ajaxCallback = nextQuestion; ajaxRequest("questions.xml"); } // wyświetl następne pytanie function nextQuestion() { questions = ajaxreq.responseXML.getElementsByTagName("q"); obj=document.getElementById("question"); if (qn < questions.length) { q = questions[qn].firstChild.nodeValue; obj.firstChild.nodeValue=q; } else { obj.firstChild.nodeValue="(no more questions)"; } } // sprawdź odpowiedź użytkownika function checkAnswer() { answers = ajaxreq.responseXML.getElementsByTagName("a"); a = answers[qn].firstChild.nodeValue; answerfield = document.getElementById("answer"); if (a == answerfield.value) { alert("Dobrze!"); } else { alert("Źle. Poprawna odpowiedź brzmi: " + a); } qn = qn + 1; answerfield.value=""; nextQuestion(); } // Ustaw funkcje obsługi zdarzeń dla przycisków obj=document.getElementById("startq"); obj.onclick=getQuestions; ans=document.getElementById("submit"); ans.onclick=checkAnswer; |
|
|
![]() ![]() |
![]() |
Aktualny czas: 14.10.2025 - 11:20 |