在這裏,我想要做的創建多選複選框值數組,如果用戶選擇推出和準備搬家意味着我想利用這個值,並通過AJAX數組形式將此值發送到下一個頁面URL,在這裏我把該值,但不能創建陣列格式,如何在jQuery的
$("#fullSearch_btn").click(function(){
var items = [];
$('#property_status:checked').each(function(){ items.push($(this).val()); });
var property_status_result = items.join(', ');
alert(items);
\t \t
});
$.ajax({
type:'GET',
url:"http://domain.com/api/get/areas/city?cityId="+city_id,
success: function(data) {
//console.log(data);
},
error:function(exception){
alert('Exeption:'+exception);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> \t
<div class="button-group">
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" style="width:100%;text-align:left; border-radius: 0px;">Property Status <span class="caret" style="text-align:right;margin-left: 50px;"></span></button>
<ul class="dropdown-menu">
<li><a href="#" class="small" data-value="option1" tabIndex="-1"><input type="checkbox" id="property_status" name="property_status[]" value="Launched" /> Launched</a></li>
<li><a href="#" class="small" data-value="option1" tabIndex="-1"><input type="checkbox" id="property_status" name="property_status[]" value="Ready To move" /> Ready To move</a></li>
<li><a href="#" class="small" data-value="option1" tabIndex="-1"><input type="checkbox" id="property_status" name="property_status[]" value="Under Construction" /> Under Construction</a></li>
<input type="submit" name="submit" value="submit" id="fullSearch_btn">
</div>
首先,ID在文檔上下文中必須是唯一的 –
使用類名代替ID,並且還應該在錨標籤外使用複選框標籤。 –