Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Kopiowanie elementow, Da rade coś takiego? :)
Apocalyptiq
post
Post #1





Grupa: Zarejestrowani
Postów: 230
Pomógł: 3
Dołączył: 8.01.2008

Ostrzeżenie: (10%)
X----


Czy w JS można jakoś kopiować elementy występujące na stronie? Np. tego diva skopiować i obok wrzucić jego kopie? Bo jeżeli pobiore jakiś element, i wrzuce go w jakieś miejsce na stronie - to po prostu go przeniose. Chcę kopiować diva, w którym jest kilka fieldsetów, a w każdym fieldsecie po 7 inputów (text). Czy jedynym wyjściem tutaj jest ręczne pobranie wartości wszystkich inputów, i utworzenie nowego diva z inputami o wartościach skopiowanych z tamtąd?


--------------------
http://estender.net - profesjonalne strony i aplikacje internetowe (Ruby on Rails, Kohana PHP)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
ziqzaq
post
Post #2





Grupa: Zarejestrowani
Postów: 428
Pomógł: 128
Dołączył: 17.06.2007

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


Łatwo się to robi np. jQuery.
Natomiast bez użycia bibliotek znalazłem coś takiego (źródło):
"We could also use insertBefore instead of appendChild, or even manually add the new element to the end of the end of the childNodes collection. Using replaceChild, we could also overwrite existing nodes. It is also possible to copy a node using cloneNode(true). This returns a copy of the node but does not automatically add it into the childNodes collection. Using element.removeChild(referenceToChildNode), we can remove existing nodes."
Natomiast nie wiem jak to się ma do różnych przeglądarek ;/

Na szybko skrobnięty kod:
  1. <?php
  2. <html>
  3. <head>
  4. <title>Tit</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript">
  7. function dodaj() {
  8.    var f = document.getElementById('frm');
  9.    var f2 = f.cloneNode(true);
  10.    window.document.childNodes[0].appendChild(f2);
  11. }
  12. </script>
  13. <style type="text/css">
  14. </style>
  15. </head>
  16. <body>
  17. <div id="frm">
  18. <form>
  19. <input type="text" name="nazwa" value="lala" />
  20. </form>
  21. </div>
  22. <div><input type="button" value="Kopiuj" onclick="dodaj();return false;"/></div>
  23. </body>
  24. </html>
  25. ?>

Sprawdziłem w Operze i Firefoxie.
Pozdrawiam winksmiley.jpg
Go to the top of the page
+Quote Post
Apocalyptiq
post
Post #3





Grupa: Zarejestrowani
Postów: 230
Pomógł: 3
Dołączył: 8.01.2008

Ostrzeżenie: (10%)
X----


DZIĘKI! biggrin.gif

Poszukałem też w dokumentacji jQuery, jest tam funkcja clone() winksmiley.jpg


--------------------
http://estender.net - profesjonalne strony i aplikacje internetowe (Ruby on Rails, Kohana PHP)
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 Aktualny czas: 21.08.2025 - 05:52