我需要serializeArray()
每次都返回选择框中的所有项目而不仅仅是当前选择的项目,因为我的selectionBox的内容可以增长或缩小.
<select multiple="multiple" id="selectionBox" >
<option value="email1@test.com">Test1</option>
<option value="email2@test.com">Test2</option>
<option value="email3@test.com">Test3</option>
<option value="email4@test.com">Test4</option>
<option value="email5@test.com">Test5</option>
</select>
Run Code Online (Sandbox Code Playgroud)
...
//Select 1 item in the select list box
formArray = $("#selectionBox").serializeArray();
alert(formArray.length); // this will be 1
//Select 5 items in the select list box
formArray = $("#selectionBox").serializeArray();
alert(formArray.length); // this will be 5
Run Code Online (Sandbox Code Playgroud)
我需要它总是返回完整的5.
我想serializeArray
只是序列化将由表单发送的值.如果你想要所有选项,你必须自己编写代码,如下所示:
var arr = [], $select = $("#selectionBox"), name = $select.attr("name");
$select.find("option").each(function() {
arr[arr.length] = { name: name, value: this.value };
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6235 次 |
最近记录: |