Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] function toggle_visibility(id) zastosowanie w PHP
MaciejStopa
post 2.01.2022, 20:36:39
Post #1





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 28.12.2021

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


cześć,
chcę zastosować funkcję function toggle_visibility(id) (JS) w PHP.
Niestety proste przepisanie z html (działającego) z wykorzystaniem echo nie działa - nie wiem jak to poprawnie przejąć.
otrzymany błąd:
Parse error: syntax error, unexpected 'foo' (T_STRING), expecting ';' or ',' in C:\xampp\htdocs\pokazdiv\index.php on line 22

pliki PHP oraz html (wklejam całość bo duże nie są)

  1. <!DOCTYPE HTML>
  2. <html lang="pl">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  6. <link rel="stylesheet" href="style.css" type="text/css" />
  7. <title>strona testowa</title>
  8. <meta name="format-detection" content="telephone=no">
  9. </head>
  10. <script type="text/javascript">
  11. function toggle_visibility(id) {
  12. var e = document.getElementById(id);
  13. if(e.style.display == 'none')
  14. e.style.display = 'block';
  15. else
  16. e.style.display = 'none';
  17. }
  18. </script>
  19. <body>
  20. <?php
  21. echo '<div id="container">';
  22. echo '<a href="#bar" name="bar" onclick= "toggle_visibility ('foo');">Read more...';
  23. echo '</a>';
  24. echo '<div id="foo" style="display:none;"><a href="" onclick="toggle_visibility('foo');">test działania';
  25. echo '</a>';
  26. echo '</div>';
  27. echo '</div>';
  28. ?>
  29. </body>
  30. </html>


  1. <!DOCTYPE HTML>
  2. <html lang="pl">
  3. <meta charset="utf-8" />
  4. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  5. <link rel="stylesheet" href="style.css" type="text/css" />
  6. <title>strona testowa</title>
  7. <meta name="format-detection" content="telephone=no">
  8. </head>
  9. <script type="text/javascript">
  10. function toggle_visibility(id) {
  11. var e = document.getElementById(id);
  12. if(e.style.display == 'none')
  13. e.style.display = 'block';
  14. else
  15. e.style.display = 'none';
  16. }
  17. <div id="container">
  18. <a href="#bar" name="bar" onclick='toggle_visibility('foo')'>Read more...</a>
  19. <div id="foo" style="display: none;"><a href="" onclick="toggle_visibility('foo');">test działania</a></div>
  20. </div>
  21. </body>
  22. </html>


z góry dziękuję za pomoc

Pozdrawiam
MS
Go to the top of the page
+Quote Post
viking
post 2.01.2022, 20:45:04
Post #2





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


\'


--------------------
Go to the top of the page
+Quote Post
MaciejStopa
post 3.01.2022, 21:53:46
Post #3





Grupa: Zarejestrowani
Postów: 2
Pomógł: 0
Dołączył: 28.12.2021

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


działa, dzięki

Pozdr
MS
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: 19.04.2024 - 18:34