2016-12-09 3 views
0

Ich möchte mehrere Checkbox-Werte nehmen, ich habe versucht, ich kann nicht bekommen, warum bedeutet hier wählen und Option nicht dort, ich habe versucht, das auf diese Weise, aber ich bin nicht in der Lage zu bekommen der WertWie bekomme ich den multiplen Wert ohne Select-Tag

<div class="dropdown-menu dropdown-menu" id="property_type2" name="property_type2" role="menu" style="color:#333;width:315px;height: 102px;border-radius:0px;" > 
 
\t <div class="chkbox" style="padding-left:5px;"> 
 
\t \t <label class="checkbox-inline checkbox-success"> 
 
\t \t <input type="checkbox" id="Check1" value="flat"> Flat 
 
\t \t </label> 
 
\t \t 
 
\t \t <label class="checkbox-inline"> 
 
\t \t <input type="checkbox" id="Check2" value="villa"> House/Villa 
 
\t \t </label> 
 
\t \t 
 
\t \t <label class="checkbox-inline"> 
 
\t \t <input type="checkbox" id="Check3" value="plot"> Plot 
 
\t \t </label> 
 
\t \t 
 
\t </div> 
 
</div> 
 

 
    var foo = []; 
 
\t \t $('.chkbox :selected').each(function(i, selected){ 
 
\t \t foo[i] = $(selected).text(); 
 
\t \t }); 
 
     console.log(foo);

+0

Es andere Probleme sein, aber sicherlich Ihre Wähler .chkbox entsprechen keine Elemente. Fügen Sie für die Checkbox-Elemente class = 'chkbox' zu html hinzu und versuchen Sie es erneut. –

Antwort

3

Ist das, was Sie suchen - https://jsfiddle.net/sekrars9/

$("#btnGetValues").click(function() { 
 
    
 
     var foo = []; 
 
     $('input[type="checkbox"]:checked').each(function() { 
 
     foo.push($(this).val()); 
 
     }); 
 
     alert(foo.join(",")); 
 
    })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> 
 
<div class="dropdown-menu dropdown-menu" id="property_type2" name="property_type2" role="menu" style="color:#333;width:315px;height: 102px;border-radius:0px;"> 
 
     <div class="chkbox" style="padding-left:5px;"> 
 
     <label class="checkbox-inline checkbox-success"> 
 
      <input type="checkbox" id="Check1" value="flat"> Flat 
 
     </label> 
 
    
 
     <label class="checkbox-inline"> 
 
      <input type="checkbox" id="Check2" value="villa"> House/Villa 
 
     </label> 
 
    
 
     <label class="checkbox-inline"> 
 
      <input type="checkbox" id="Check3" value="plot"> Plot 
 
     </label> 
 
     <input type="button" id="btnGetValues" value="Get Values"> 
 
     </div> 
 
    </div>

0

Nach HTML wird nach Ihrem Bedarf arbeiten:

<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 


<script type="text/javascript"> 
$(document).ready(function(){ 
     $.each($('input'),function(){ 

     if($(this).is(':checked')) 
      console.log($(this).val()); 
     }); 
}); 
</script> 
</head> 

<body> 
<div class="dropdown-menu dropdown-menu" id="property_type2" name="property_type2" role="menu" style="color:#333;width:315px;height: 102px;border-radius:0px;" > 
    <div class="chkbox" style="padding-left:5px;"> 
     <label class="checkbox-inline checkbox-success"> 
      <input type="checkbox" id="Check1" value="flat"> Flat 
     </label> 

     <label class="checkbox-inline"> 
      <input type="checkbox" id="Check2" value="villa"> House/Villa 
     </label> 

     <label class="checkbox-inline"> 
      <input type="checkbox" id="Check3" value="plot"> Plot 
     </label> 

    </div> 
</div> 

</body> 

</html> 
Verwandte Themen