2016-07-08 11 views
0

私はチェックした項目の値を取得するためにこのコードを使用しました。それは私のプロジェクトで働いていません。私はちょうど私がそれが288,289,290のようにコンマ区切り と私のテキストボックスに行くことを確認したすべての値が欲しい。事前のおかげでチェックボックスの値は、テキストボックスにコンマで区切られています

<input type="text" name="holder" id="holder" 
    <input type="checkbox" name="example[]" value="288" checked/> 
    <input type="checkbox" name="example[]" value="289" checked/> 
    <input type="checkbox" name="example[]" value="290" /> 
    <input type="checkbox" name="example1[]" value="289" checked/> 

    var output = jQuery.map($(':checkbox[name="example[]"]:checked'), function (n, i) { 
     return n.value; 
    }).join(','); 

    alert(output); 

答えて

0
<!DOCTYPE html> 
<html> 
<head> 
<script src="http://code.jquery.com/jquery-latest.js"></script> 
<meta charset=utf-8 /> 
<title>JS Bin</title> 
</head> 

<body> 
    <div id="inputs"> 
    <input type="checkbox" value="Apple"> 
    <input type="checkbox" value="Orange"> 
    <input type="checkbox" value="Pineapple"> 
    <input type="checkbox" value="Mango"> 
    </div> 
    <input type="text" id="target"/> 
</body> 
</html> 
var arr = []; 
$('#inputs input').change(function() { 
    if (this.checked) { 
    arr.push(this.value); 
    } 
    else { 
    arr.splice(arr.indexOf(this.value), 1); 
    } 
    $('#target').val(arr + ''); 
}); 
+0

私はちょうど私の問題を解決 –

関連する問題