Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript]Blokowanie checkboxem pola input text
Forum PHP.pl > Forum > Przedszkole
arzach
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.  
Comandeer
Kod
$(this).nextSibling().prop('disabled', !this.checked);
arzach
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
arzach
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.
Comandeer
Bo td nie jest closest (to nie sąsiad), tylko parent (rodzic)
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.