Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript][HTML]motools getElementsByClassName is not a function
casperii
post
Post #1





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

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


Panowie mam kod:


  1. function load_calendar(el,month,year){
  2. var req = new Request({
  3. async:false,
  4. method: 'get',
  5. url: url_ajax_cal,
  6. data: {
  7. 'id_item':id_item,
  8. 'month':month,
  9. 'year':year,
  10. 'lang':lang
  11. },
  12. evalScripts:true,
  13. onRequest: function() {
  14. el.set('html','<img class="img_loading_month" src="'+img_loading_month+'">');
  15. },
  16. onSuccess: function(response) {
  17. el.set('html',response);
  18.  
  19. $('the_months').getElementsByClassName('.weekend').each(function(el) {
  20. });
  21.  
  22. if(clickable_past=="off"){
  23. $('the_months').getElementsByClassName('.past').each(function(el) {
  24. el.set('opacity','0.6');
  25. });
  26. }
  27.  
  28. }
  29. }).send();
  30. }


konsola krzyczy do tego:
$('the_months').getElementsByClassName('.weekend').each(function(el) {


html:
  1. <li class=" clickable weekend " id="date_2017-07-01" title="1/07/2017 - Wolne" data-date="1/07/2017" style="cursor: pointer; visibility: visible; zoom: 1; opacity: 1;">1</li>

Go to the top of the page
+Quote Post
markuz
post
Post #2





Grupa: Zarejestrowani
Postów: 1 240
Pomógł: 278
Dołączył: 11.03.2008

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


Nie odróżniasz zwykłego JavaScript DOM od jQuery..
$ to selector jQuery.
getElementsByClassName to czysty JavaScript.
Co oznacza 'the_months' według Ciebie?


--------------------
Go to the top of the page
+Quote Post
trueblue
post
Post #3





Grupa: Zarejestrowani
Postów: 6 806
Pomógł: 1828
Dołączył: 11.03.2014

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


Mieszasz metody jQuery z metodami z czystego JS.
Przeoczyłem i tytuł i kod.
MooTools rozszerza natywne typy o swoje metody, więc można się odwołać metodą z czystego JS do obiektu zwracanego przez MooTools.
Ale nie na odwrót, a odwołujesz się do kolekcji elementów metodą z MooTools.
Albo tak:
  1. $$('#the_months .weekend').each(function(el){});

albo:
  1. [].forEach.call($('the_months').getElementsByClassName('weekend'),function(el){});

ewentualnie:
  1. [].forEach.call($$('#the_months .weekend'),function(el){});


Ten post edytował trueblue 25.06.2017, 20:20:46


--------------------
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 - 01:55