Select2 with checkbox list for multiple selection but not getting values
P粉399585024
2023-08-31 17:54:42
<p>使用此代码,它可以工作。但没有在 $('form').serialize(); 中获取选定的值</p>
<pre class="brush:php;toolbar:false;">$('.select2-multiple').select2MultiCheckboxes({
placeholder: "Choose multiple elements",
})
<div class="row">
<form id="search_vendor_form">
<select name="sel-01[]" id="sel-01" class="select2-multiple">
<option></option>
<option value="AL">Alabama</option>
<option value="CA">California</option>
<option value="NY">New York</option>
<option value="TX">Texas</option>
<option value="WY">Wyoming</option>
</select>
</div>
</form>
<div class="row">
</div>
<div class="row">
</div>
jQuery(function($)
{
$('.select2-multiple').select2MultiCheckboxes({
placeholder: "Choose multiple elements",
})`your text`
});
$(document).on('change','#sel-01',function(){
console.log($(#search_vendor_form).serialize())
})</pre>
<p>我想在ajax中发送表单值,但不进入console.log($(#search_vendor_form).serialize())</p>
"your text"
as the string after the function, which is invalid and may be a bug.jQuery(function($){ ... )}
inside the function.The following should solve this problem: