1
ここで私はjson形式で配列を作成したいと思っていますが、すべてのことをしましたが、テキストフィールドを入力して使用するオプションを選択したい、json形式の配列を作ることができない、私はこのために1時間以上を費やしたが、私はよく理解した場合、私は解決策json形式で配列を作成する方法選択
function createJSON() {
result = [];
$("input[class=email]").each(function() {
\t \t var email = $(this).val();
\t \t \t var items = [];
\t \t \t $('.Check1:checked').each(function(){
\t \t \t \t items.push($(this).val());
\t \t \t \t });
\t \t $("input[class=mobile]").each(function() {
\t \t \t var mobile = $(this).val();
\t \t
\t \t result.push({email: email,mobile: mobile, multiselect: items})
\t \t });
});
console.log(result);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<form method="POST">
Email<input title="Title1" type="text" class="email" >
<input title="Title2" type="text" class="mobile">
<div class="col-md-4" style="padding-left: 4px; padding-right: 4px;">
\t <li style="color: #333; font-size: 85%;">
\t <input type="checkbox" class="Check1" name="listing_type[]" value="Office Space"> Office Space \t \t \t \t \t \t \t \t
\t </li>
</div>
<div class="col-md-4" style="padding-left: 4px; padding-right: 4px;">
\t <li style="color: #333; font-size: 85%;">
\t <input type="checkbox" class="Check1" name="listing_type[]" value="Apartment"> Apartment \t \t \t \t \t \t \t \t
\t </li>
</div>
<div class="col-md-4" style="padding-left: 4px; padding-right: 4px;">
\t <li style="color: #333; font-size: 85%;">
\t <input type="checkbox" class="Check1" name="listing_type[]" value="Villament"> Villament \t \t \t \t \t \t \t \t
\t </li>
</div>
<div class="col-md-4" style="padding-left: 4px; padding-right: 4px;">
\t <li style="color: #333; font-size: 85%;">
\t <input type="checkbox" class="Check1" name="listing_type[]" value="Individual House"> Individual House \t \t \t \t \t \t \t
</div>
<div class="col-md-4" style="padding-left: 4px; padding-right: 4px;">
\t <li style="color: #333; font-size: 85%;">
\t <input type="checkbox" class="Check1" name="listing_type[]" value="Row House"> Row House
</div>
<input type="button" id="btn-submit" value="submit" onClick="createJSON()">
</form>
使用例を作りますか? –