Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: ukrywanie wielu td
Forum PHP.pl > Forum > Po stronie przeglądarki
Dex1987
Witam,

mam taki kodzik

  1.  
  2. function ShowHide (open, close) {
  3.  
  4.                   if (open != '') {
  5.  
  6.                       expMenu (open);
  7.                   }
  8.  
  9.                   if (close != '') {
  10.  
  11.                       expMenu (close);
  12.                   }
  13. }
  14.  
  15. function expMenu (id) {
  16.  
  17.                  var item = null;
  18.  
  19.                  if (document.getElementById) {
  20.  
  21.                      item = document.getElementById(id);
  22.  
  23.                  } else if (document.all) {
  24.  
  25.                             item = document.all[id];
  26.  
  27.                  } else if (document.layers){
  28.  
  29.                             item = document.layers[id];
  30.                  }
  31.  
  32.                  if (!item) {
  33.  
  34.                      // do nothing
  35.  
  36.                  } else if (item.style) {
  37.  
  38.                             if (item.style.display == "none") {
  39.  
  40.                                 item.style.display = "";
  41.  
  42.                             } else {
  43.  
  44.                                 item.style.display = "none";
  45.                             }
  46.  
  47.                  } else {
  48.  
  49.                             item.visibility = "show";
  50.                  }
  51. }
  52.  
  53.  
  54.      <table border="0" align="center" cellpadding="0" cellspacing="0" width="90%" height="1">
  55.        <tr>
  56.          <td height="25" width="249" valign="top">
  57.            <font face="Verdana" size="2" color="#094AAC">
  58.              <a href="javascript:ShowHide('qr_opena1175','qr_closeda1175');">+ Menu główne</a>
  59.            </font>
  60.          </td>
  61.        </tr>
  62.        <tr id="qr_opena1175" style="display:none;position:relative;">
  63.              <td height="25" style="border-bottom: 1px solid #E8E8E8;" onmouseover="style.backgroundColor='#F9F9F9';" onmouseout="style.backgroundColor='#FFFFFF';" width="249">
  64.                <font color="#4A4A4A" face="Verdana" size="2">
  65.                  <a href="home.html">&nbsp;&nbsp;&nbsp;Strona główna</a>
  66.                </font>
  67.              </td>
  68.            </tr>      
  69.        <tr id="qr_opena1175" style="display:none;position:relative;">
  70.              <td height="25" style="border-bottom: 1px solid #E8E8E8;" onmouseover="style.backgroundColor='#F9F9F9';" onmouseout="style.backgroundColor='#FFFFFF';" width="249">
  71.                <font color="#4A4A4A" face="Verdana" size="2">
  72.                  <a href="home.html">&nbsp;&nbsp;&nbsp;Strona główna</a>
  73.                </font>
  74.              </td>
  75.            </tr>
  76.        </table>


i teraz chce zrobic tak zeby po kliknieciu na "menu glowne" pokazywaly sie wszystkie komorki a nie tylko pierwsza. Zastanawiam sie jeszcze czy nie mozna tego kodu uproscic?

Z gory dzieki za odpowiedz, pozdrawiam dex.
Zajec
Cytat(Dex1987 @ 2006-04-10 13:27:04)
Zastanawiam sie jeszcze czy nie mozna tego kodu uproscic?.

  1. <script type="text/javascript">
  2.  
  3. function ShowHide (open, close) {
  4.      if (open != '')
  5.      expMenu(open);
  6.      if (close != '')
  7.      expMenu(close);
  8. }
  9.  
  10. function expMenu(id) {
  11.      var item = document.getElementById(id);
  12.  
  13.      if (item.style)
  14.      {
  15.            if (item.style.display == "none")
  16.            item.style.display = "";
  17.            else
  18.            item.style.display = "none";
  19.      }
  20. }
  21.  
  22. </script>
Dex1987
niestety dziala tak jak dzialalo tyle ze po 2 kliknieciu sie juz nie chowa winksmiley.jpg
Zajec
W moim poprzednim kodzie była linijka
Kod
tem.style.display = "none";
zamiast
Kod
item.style.display = "none";
. Poprawiłem.
Dex1987
ok dziala tak jak dzialalo, pokazuje sie (chowa sie) tylko pierwszt td/tr.

Pozdrawiam dex.
revyag
Nie możesz nadawać wierszom tego samego id. Jeśli już chcesz z tego korzystać to dla każdego zrób unikalne.
Poza tym da się to prościej zrobić smile.gif
Kod
<style type="text/css">
table tr.none {
    display:none;
}
table tr.visible {
    display:table-row;
}
</style>

Kod
<script type="text/javascript">
function ShowHide() {
    var trs = document.getElementsByTagName("tr");

    for (i in trs) {
        if(trs[i].className == 'none') {
            trs[i].className = 'visible'
        } else {
            if(trs[i].className == 'visible') {
                trs[i].className = 'none'
            }
        }
    }
}
</script>


  1. <table border="0" align="center" cellpadding="0" cellspacing="0" width="90%" height="1">
  2.       <tr>
  3.         <td height="25" width="249" valign="top">
  4.           <font face="Verdana" size="2" color="#094AAC">
  5.             <a href="javascript:ShowHide();">+ Menu główne</a>
  6.           </font>
  7.         </td>
  8.       </tr>
  9.       <tr class="none">
  10.             <td height="25" style="border-bottom: 1px solid #E8E8E8;" onmouseover="style.backgroundColor='#F9F9F9';" onmouseout="style.backgroundColor='#FFFFFF';" width="249">
  11.               <font color="#4A4A4A" face="Verdana" size="2">
  12.                 <a href="home.html">&nbsp;&nbsp;&nbsp;Strona główna</a>
  13.               </font>
  14.             </td>
  15.           </tr>      
  16.       <tr class="none" >
  17.             <td height="25" style="border-bottom: 1px solid #E8E8E8;" onmouseover="style.backgroundColor='#F9F9F9';" onmouseout="style.backgroundColor='#FFFFFF';" width="249">
  18.               <font color="#4A4A4A" face="Verdana" size="2">
  19.                 <a href="home.html">&nbsp;&nbsp;&nbsp;Strona główna</a>
  20.               </font>
  21.             </td>
  22.           </tr>
  23.       </table>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.