Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JS]Dodawanie linkow
szaryBURY
post
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 11.07.2012

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


Witam chcialbym dodac normalny htmlowski link poprze js. Chcialby to zrobic tworzac nowy element i przyporzadkowujac go jako dziecko innego elementu. Probuje cos takiego

  1. <script type="text/javascript">
  2. window.onload = Laduj;
  3.  
  4. function Laduj()
  5. {
  6.  
  7.  
  8.  
  9. var newlink = document.createElement('a');
  10. newlink.setAttribute('href', 'index.php');
  11. di = document.getElementById('mis');
  12. di.appendChild(newlink);
  13.  
  14.  
  15. }
  16. </head>
  17.  
  18. <div id="mis">kupa</div>
  19. </body>
  20. </html>


Lecz nic sie nie dzieje. Co powinienem dodac/zmodyfikowac?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kamil4u
post
Post #2





Grupa: Zarejestrowani
Postów: 2 350
Pomógł: 512
Dołączył: 4.01.2009
Skąd: Wrocław / Świdnica

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


Cytat
Te cfaniak

?

Cytat
inner html nie jest zgodny z DOMem

Skąd te nieprawdziwe informacje?

Użyj: innerText, textContent lub innerText . Każda przeglądarka ma trochę inaczej. Poczytaj!
Go to the top of the page
+Quote Post
szaryBURY
post
Post #3





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 11.07.2012

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


Cytat(kamil4u @ 11.07.2012, 23:31:31 ) *
?


Skąd te nieprawdziwe informacje?

Użyj: innerText, textContent lub innerText . Każda przeglądarka ma trochę inaczej. Poczytaj!


Przepraszam, takl chcialem ubarwic troche dyskusje. A informacje przeczytalem w paru tutorialach.

Tak naprawde moj kod zwiazany jest z tworzeniem SVG

  1. var svgns = "http://www.w3.org/2000/svg";
  2. var xlinkns = "http://www.w3.org/1999/xlink";
  3.  
  4. var ATTR_MAP = {
  5. "className": "class",
  6. "svgHref": "href"
  7. }
  8.  
  9. var NS_MAP = {
  10. "svgHref": xlinkns
  11. };
  12.  
  13. function makeSVG(tag, attributes) {
  14. var elem = document.createElementNS(svgns, tag);
  15. for (var attribute in attributes) {
  16. var name = (attribute in ATTR_MAP ? ATTR_MAP[attribute] : attribute);
  17. var value = attributes[attribute];
  18. if (attribute in NS_MAP)
  19. elem.setAttributeNS(NS_MAP[attribute], name, value);
  20. else
  21. elem.setAttribute(name, value);
  22. }
  23. return elem;
  24. }


kiedy zrobie sobie
  1. var text = makeSVG("text", {id: "text1", x: "60", y: "60"});

i dodam text node jest ok.
Niestety przy dodaniu elementu "a" nic sie nie wyswietla.

Wiem ze pewnie powinienem uzyc innych tagow typu a, niestety nic nie daje rezultatu. Jakies podpowiedzi?

Ten post edytował szaryBURY 12.07.2012, 11:24:08
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: 7.10.2025 - 04:06