Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Wyszukiwanie obrazka i modyfikowanie stringi
baracuda
post
Post #1





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 2.02.2022

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


Witam serdecznie,
Mam na stronie treści pobierane z bazy danych.

Załóżmy że mam zmienną $txt ze stringiem.

Zdarzają się w nich nich obrazki w różnych postaciach:
- <img alt="XXXX" class="img-fluid" src="random.name" style="height:930px; width:620px" />
- <img alt="XXXX" class="img-fluid" src="random.name"/>
- <img src="random.name"/>
etc

Potrzebuję dodać do każdego obrazka: class "picla" and data-label-class="label-class" - czyli w rezultacie:
- <img alt="XXXX" class="img-fluid picla" src="random.name" style="height:930px; width:620px" data-label-class="label-class"/>
- <img alt="XXXX" class="img-fluid picla" src="random.name" data-label-class="label-class"/>
- <img class="picla" src="random.name" data-label-class="label-class"/>


Wie ktoś może jak to zrobić?(IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
baracuda
post
Post #2





Grupa: Zarejestrowani
Postów: 14
Pomógł: 0
Dołączył: 2.02.2022

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


Cytat(trueblue @ 10.05.2022, 09:13:31 ) *


Tak, chodzi o PICLA (IMG:style_emoticons/default/smile.gif)

zrobiłem taki kod:

  1. $('.content-view img').each(function() {
  2. if ($(this).hasClass('picla') === false) {
  3. $(this).addClass('picla');
  4. $(this).attr('data-label-class', 'label-class');
  5. console.log('- dodaje do' + $(this).attr('src'));
  6. }
  7. });



ale nie dodaje napisów na zdjęciu (jak dodam ręcznie z poziomu kodu html to działa).

JS byłļy lepszy, ale nie chce działać (IMG:style_emoticons/default/sad.gif) Chyba że robi się to jakoś inaczej?
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: 14.10.2025 - 20:38