Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> widoczny/niewidoczny div, alternatywa dla getElementById
fiszol
post
Post #1





Grupa: Zarejestrowani
Postów: 453
Pomógł: 16
Dołączył: 25.05.2004
Skąd: Gorzów Wlkp.

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


  1. <script type="text/javascript">
  2. <!--
  3. function blink(id)
  4. {
  5. document.getElementById(id).style.display = (document.getElementById(id).style.display == "none") ? "block" : "none";
  6. }
  7. -->
  8.  
  9. <a href="java script:blink('tha-form')">pokaz / ukryj</a>
  10. <div id="tha-form" style="display:none">troche jestem, troche mnie nie ma</div>


Wszystko by było super gdyby nie to że chcem w diva wsadzić formularz który będzie wyśiwetlanie kilka razy na stronie (dodaj komentarz do newsa), a jak wiadomo użyty id zawsze musi być unikalny, jak rozwiązać ten problem?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
jarekh
post
Post #2





Grupa: Zarejestrowani
Postów: 13
Pomógł: 0
Dołączył: 4.06.2007

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


Aby zrobic cos na wielu elmentach mozna zrobic tak:
  1. var elements = document.getElementsByTagName('div');
  2. for (var i=0;i<elements.length;i++)
  3. {
  4. if(elements[i].getAttribute('rel')=='formularz'){
  5. elements[i].style.display = (elements[i].style.display == "none") ? "block" : "none";
  6. }
  7. }
  8.  
  9. <div rel='formularz'>pierwszy</div>
  10. <div rel='formularz'> drugi</div>


Ten post edytował jarekh 20.06.2007, 05:41:52
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 6.10.2025 - 23:59