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>
這是我的工作例如一個例子嗎? –