Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> tworzenie div w js
bartek6949
post
Post #1





Grupa: Zarejestrowani
Postów: 89
Pomógł: 1
Dołączył: 18.05.2009

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


mam oto taki skrypt ktory powinien tworzyc div w js a dokladnej powinien tworzy nowy div i wrzuca go do diva id="a" oto kod pilnie potrzebuje pomocy
  1. function createDiv()
  2. {
  3. var divTag = document.createElement('div');
  4.  
  5. divTag.id = 'div1';
  6.  
  7. divTag.setAttribute('background','transparent url(assassin.png) no-repeat');
  8. divTag.setAttribute('height','35px');
  9. divTag.setAttribute('left','36px');
  10. divTag.setAttribute('top','18px');
  11. divTag.setAttribute('position','absolute');
  12. divTag.setAttribute('width','35px');
  13.  
  14.  
  15.  
  16. document.getElementById('a').appendChild(divTag);
  17. }
  18. new createDiv();


Ten post edytował bartek6949 5.11.2009, 22:20:33
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




Cytat
Chyba chodzi o to że nie może dodać id
No to jak już tak chybujemy....:
Cytat
divTag.setAttribute('background','transparent url(assassin.png) no-repeat');
divTag.setAttribute('height','35px');
divTag.setAttribute('left','36px');
divTag.setAttribute('top','18px');
divTag.setAttribute('position','absolute');
divTag.setAttribute('width','35px');

To nie są atrybuty. Te rzeczy należą do STYLE, które to jest atrybutem. Powinno to wyglądać mniej więcej tak:
divTag.style.height = 36;
....
Piszę 'mniej więcej', gdyż nie zawsze nazwa jest odzwierciedleniem tego co ma być po 'style.'

Uzyłbyś jQuery i się nie bawił w takie pierdoły (IMG:style_emoticons/default/winksmiley.jpg)
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: 15.10.2025 - 01:09