我有小组列表:
<select multiple="multiple" name="groups[]" id="groups[]" class="myclass">
<option value="1">Employee</option>
<option value="2">Suppliers</option>
<option value="3">Customers</option>
</select>
我使用以下代码将组传递给ajax网址,但只传递一组!!
<Script>
groups=document.getElementById("groups[]").options.item(addIndex).value;
xmlHttp.open("POST","?action=ajaxcontac&groups="+ groups,true);
</Script>
如何将多个组传递给网址?
由于
答案 0 :(得分:1)
答案 1 :(得分:1)
var opts = document.querySelectorAll("#groups\\[\\] option"),
groups = [].map.call(opts, function(option) {
if (option.selected) {
return "groups[]=" + option.value;
}
}).filter(Boolean).join("&");
xmlHttp.open("POST", "?action=ajaxcontac&" + groups, true);
演示