Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [JavaScript]Blokowanie checkboxem pola input text
arzach
post 26.05.2015, 15:24:31
Post #1





Grupa: Zarejestrowani
Postów: 332
Pomógł: 6
Dołączył: 27.11.2008

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


Tak jak w temacie jak zablokować checkboxem pola input text

Obecnie mam taki kod
  1. <!doctype html>
  2. <html lang="en">
  3. <meta charset="utf-8">
  4. <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  5. </head>
  6.  
  7.  
  8.  
  9.  
  10. <input type="checkbox" name="add_time_check[]" /> <input type="text" name="add_time[]" disabled="disabled" /><br/>
  11. <input type="checkbox" name="add_time_check[]" /> <input type="text" name="add_time[]" disabled="disabled" /><br/>
  12. <input type="checkbox" name="add_time_check[]" /> <input type="text" name="add_time[]" disabled="disabled" /><br/>
  13. <input type="checkbox" name="add_time_check[]" /> <input type="text" name="add_time[]" disabled="disabled" /><br/>
  14.  
  15.  
  16. $( document ).ready(function() {
  17.  
  18. $("input[add_time_check[]]").click(function() {
  19. alert("Dzia_a!!!");
  20. });;
  21.  
  22. });
  23.  
  24.  
  25.  
Go to the top of the page
+Quote Post
Comandeer
post 26.05.2015, 15:26:54
Post #2





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

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


Kod
$(this).nextSibling().prop('disabled', !this.checked);


--------------------
Go to the top of the page
+Quote Post
arzach
post 27.05.2015, 14:35:41
Post #3





Grupa: Zarejestrowani
Postów: 332
Pomógł: 6
Dołączył: 27.11.2008

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


Nie działa bo odwołując się w ten sposób
  1. $("input[add_time_check[]]").click(function() {

Do elementu tablicy to nie działa
Go to the top of the page
+Quote Post
fate
post 27.05.2015, 14:58:40
Post #4





Grupa: Zarejestrowani
Postów: 824
Pomógł: 106
Dołączył: 14.03.2012
Skąd: Warszawa

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


http://jsfiddle.net/rb6f1kz5/

https://api.jquery.com/attribute-equals-selector/
http://jsfiddle.net/rb6f1kz5/1/

@up
https://api.jquery.com/siblings/
https://api.jquery.com/next/


--------------------
Go to the top of the page
+Quote Post
arzach
post 31.05.2015, 12:23:44
Post #5





Grupa: Zarejestrowani
Postów: 332
Pomógł: 6
Dołączył: 27.11.2008

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


OK poradziłem sobie ale mam inny problem ponieważ jak mam te pola input w tabelce to nie chce już działać.
Jak temu zaradzić questionmark.gifquestionmark.gif?

Próbowałem coś z find ale nie działa

Mam taki kod

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  6. </head>
  7.  
  8. <body>
  9.  
  10. <table cellpadding='0' cellspacing='1' width='450'>
  11. <tr>
  12. <td align='right' width='1%'>
  13. <input type="checkbox" name="add_time_check[]" />
  14. </td><td align='right' width='1%'> <input type="text" name="add_time[]" disabled="disabled" /></td>
  15. </tr>
  16. <tr>
  17. <td align='right' width='1%'>
  18. <input type="checkbox" name="add_time_check[]" />
  19. </td><td align='right' width='1%'> <input type="text" name="add_time[]" disabled="disabled" /></td>
  20. </tr>
  21. <tr>
  22. <td align='right' width='1%'>
  23. <input type="checkbox" name="add_time_check[]" />
  24. </td><td align='right' width='1%'> <input type="text" name="add_time[]" disabled="disabled" /></td>
  25. </tr>
  26. <tr>
  27. <td align='right' width='1%'>
  28. <input type="checkbox" name="add_time_check[]" />
  29. </td><td align='right' width='1%'> <input type="text" name="add_time[]" disabled="disabled" /></td>
  30. </tr>
  31.  
  32.  
  33.  
  34. </table>
  35.  
  36.  
  37.  
  38. $(document).ready(function () {
  39.  
  40. $("input[name='add_time_check[]']").click(function () {
  41. if (this.checked){
  42.  
  43.  
  44. $(this).closest('td').next().find('input[name='add_time[]']').prop("disabled", false);
  45. } else {
  46. $(this).closest('td').next().find('input[name='add_time[]']').prop("disabled", true);
  47. }
  48.  
  49.  
  50.  
  51.  
  52. }); ;
  53. });
  54.  
  55.  
  56. </script>
  57.  
  58.  
  59.  
  60. </body>
  61.  
  62. </html>
  63.  


Proszę o pomoc.

Ten post edytował arzach 31.05.2015, 12:40:25
Go to the top of the page
+Quote Post
Comandeer
post 31.05.2015, 13:07:45
Post #6





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

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


Bo td nie jest closest (to nie sąsiad), tylko parent (rodzic)


--------------------
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: 24.07.2025 - 16:07