2017-12-25 3 views
0

mit nur einer in einer Reihe Kontrollkästchen aktiviert, wie man überprüft, um nur in einzeiligen Checkbox mit Hilfe von Javascriptwie Javascript

hier ist meine Ansicht

<?php $c=0; for($a=0; $a < 5; $a++) { ?> 
<table> 
<tr class="cbclass"> 
<td><input type="checkbox" name="cbname" value="1" id="cb" class="cb"></td> 
<td><input type="text" name="f_nilai1[]" id="id_tnilai<?php echo $c++; ?>" ></td> 

<td><input type="checkbox" name="cbname" value="1" id="cb" class="cb"></td> 
<td><input type="text" name="f_nilai2[]" id="id_tnilai<?php echo $c++; ?>" ></td> 

<td><input type="checkbox" name="cbname" value="1" id="cb" class="cb"></td> 
<td><input type="text" name="f_nilai3[]" id="id_tnilai<?php echo $c++; ?>"></td> 

<td><input type="checkbox" name="cbname" value="1" id="cb" class="cb"></td> 
<td><input type="text" name="f_nilai4[]" id="id_tnilai<?php echo $c++; ?>"></td> 

<td><input type="checkbox" name="cbname" value="1" id="cb" class="cb"></td> 
<td><input type="text" name="f_nilai5[]" id="id_tnilai<?php echo $c++; ?>"></td> 
</tr> 

das ist mein Javascript Ich habe bereits Wert in Eingabetext geändert, wenn das Kontrollkästchen angeklickt wird, ich benutze es, weil insert_batch checkbox nicht post, wenn Null, also verwende ich Eingabetext, um es zu posten, und es läuft gut. Als nächstes möchte ich nur in einer Zeile überprüft werden, kann mir jemand helfen ??

<script type="text/javascript"> 
 
$(document).ready(function() 
 
{ 
 
var a = $(".cb").length;  \t \t \t \t \t \t \t \t \t \t 
 
    $(".cb").click(function(event) 
 
    { 
 
    for(var i=0; i<a; i++) { 
 
    \t var check = document.getElementsByName('cbname'); 
 
    \t  if(check[i].checked) 
 
     { 
 
    \t \t $("#id_tnilai"+[i]).val(1); 
 
    \t \t } else { 
 
    \t \t $("#id_tnilai"+[i]).val(0); 
 
    \t \t } 
 
    \t } 
 
    \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t 
 
    }); 
 
}); 
 
</script>

Antwort

0

Sie können die silblings des aktuellen Kontrollkästchen finden und die geprüfte Eigenschaft dieser silbilings zu keiner ändern. Code unten angegeben.

<script type="text/javascript"> 
$(document).ready(function() 
{ 
var a = $(".cb").length;            
    $(".cb").click(function(event) 
    { 
    var siblings = $(this).parent().siblings(); 
    for (var i = 0; i < siblings.length; i++) { 
     $(siblings[i]).children().filter('input[type="checkbox"]').prop('checked',''); 
    } 
    for(var i=0; i<a; i++) { 
     var check = document.getElementsByName('cbname'); 
      if(check[i].checked) 
     { 
      $("#id_tnilai"+[i]).val(1); 
      } else { 
      $("#id_tnilai"+[i]).val(0); 
      } 
     } 

    }); 
}); 
</script> 

Hoffe, dass dies Ihr Problem lösen wird. Danke

+0

danke viel Arbeit für mich, eine weitere Frage bitte .... wie Hintergrundfarbe des Elements ändern (nur eine Reihe) in 'rot' wenn Wert f_nilai2 [] == 1 Ich versuche es oft, aber es ist fehlgeschlagen – Hamidi