In meinem Projekt möchte ich Checkbox Wert in Array zu instorieren.Wie bekomme ich Checkbox-Wert und speichere in einem Array
Hier ist mein Code:
$('#fpdId').click(function(){
var files = new Array();
//xzyId is table id.
$('#xzyId tbody tr input:checkbox').each(function() {
if (this.checked) {
files.push(this.value);
}
});
console.log(files);
});
<input type="button" id="fpdId" value="filePack">
Meine HTML-Tabelle hat drei Zeilen und jede Zeile hat drei tds
Hier Codetabelle:
<table border=1px class="xzy" id="xzyId" style="width:100%">
<colgroup>
<col style="width:10%">
<col style="width:80%">
<col style="width:10%">
</colgroup>
<tbody>
<tr>
<td ><input type="checkbox" value="x" >1</td>
<td >Stack</td>
<td >John</td>
</tr>
<tr>
<td ><input type="checkbox" value="y" >2</td>
<td >Stack</td>
<td >Sansa</td>
</tr>
<tr>
<td ><input type="checkbox" value="z" >3</td>
<td >Stack</td>
<td >Aya</td>
</tr>
</tbody>
</table>
Aber Pech, das Array leer, was ist los?
können Sie HTML-Teil der Tabelle ,, mit Form und Kontrollkästchen hinzufügen? –
hast du es schon mal versucht? hier ist es https://stackoverflow.com/questions/11292778/use-jquery-to-get-values-of-selected-checkboxes –
Sie haben Code in jquery gegeben, aber das Tag ist Javascript –