Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]zmiana css wiersza w tabeli po zaznaczeniu lub odznaczeniu checkboxa
uki8877
post 11.05.2016, 21:58:36
Post #1





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 27.03.2016

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


Witam

Czy w js mozna cos takiego wykonac ?

zalozmy ze mamy taki kod >

  1. <tr class="">
  2. <td><input type="checkbox" class="checkboxField" ></td>
  3. </tr>
  4. <tr class="">
  5. <td><input type="checkbox" class="checkboxField" ></td>
  6. </tr>
  7. <tr class="">
  8. <td><input type="checkbox" class="checkboxField" ></td>
  9. </tr>
  10. <tr class="">
  11. <td><input type="checkbox" class="checkboxField" ></td>
  12. </tr>


i chcialbym aby po zaznaczeniu checkboxa do wiersza w ktorym znajduje sie ten checkbox zostala dodana jakas klasa. jest to mozliwe ?
Go to the top of the page
+Quote Post
mariolita
post 11.05.2016, 22:18:56
Post #2





Grupa: Zarejestrowani
Postów: 116
Pomógł: 10
Dołączył: 24.04.2015

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


w JQUERY moze być?

  1. <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
  2.  
  3. <script>
  4.  
  5. $( document ).ready(function() {
  6.  
  7. $(".checkboxField").click( function() {
  8.  
  9. $(this).addClass("innaKLASA");
  10.  
  11. });
  12.  
  13. });
  14.  
  15. </script>


https://jsfiddle.net/a4ojgcm1/
Go to the top of the page
+Quote Post
uki8877
post 11.05.2016, 22:21:51
Post #3





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 27.03.2016

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


moze byc w jQuery, tylko Twoj kod dodaje klase do checkboxa ,a nie do wiersza tabeli
Go to the top of the page
+Quote Post
mariolita
post 11.05.2016, 22:55:30
Post #4





Grupa: Zarejestrowani
Postów: 116
Pomógł: 10
Dołączył: 24.04.2015

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


https://jsfiddle.net/zocLn58r/

  1. <table id="tabela" border="1" align="center">
  2.  
  3. <tr class="">
  4. <td ><input type="checkbox" class="checkboxField" ></td>
  5. </tr>
  6.  
  7. <tr class="">
  8. <td ><input type="checkbox" class="checkboxField" ></td>
  9. </tr>
  10.  
  11. <tr class="">
  12. <td ><input type="checkbox" class="checkboxField" ></td>
  13. </tr>
  14.  
  15. <tr class="">
  16. <td ><input type="checkbox" class="checkboxField" ></td>
  17. </tr>
  18.  
  19. </table>
  20.  
  21. <script src="https://code.jquery.com/jquery-1.12.3.min.js"></script>
  22.  
  23. <script>
  24.  
  25. $(document).ready(function(){
  26.  
  27. $(".checkboxField").click(function(){
  28.  
  29. $('#tabela input[type="checkbox"]:checked').each(function(){
  30.  
  31. $(this).parents('tr').addClass("dodanaKlasa");
  32.  
  33. alert($(this).parents('tr').attr("class"));
  34.  
  35. });
  36.  
  37. });
  38.  
  39. });
  40.  
  41. </script>
Go to the top of the page
+Quote Post
uki8877
post 12.05.2016, 12:46:27
Post #5





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 27.03.2016

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


OKI, a jesli chcialbym odwolac sie nie do rodzica (tr) tylko do kolumny (td) o jakiejs klasie ?
czyli mam kod:

<tr class="">
<td class="age">20</td>
<td><input type="checkbox" class="checkboxField" ></td>
</tr>
<tr class="">
<td class="age">21</td>
<td><input type="checkbox" class="checkboxField" ></td>
</tr>

probowalem tak :
  1. alert($this.parent().siblings().find('td .age').text());


jednak alert nic nie wyswietla, konsola rowniez. Jakies pomysly ?

ok ,pomogło ->

  1. alert($this.parent().siblings(".age").text());
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 Wersja Lo-Fi Aktualny czas: 20.07.2025 - 06:20