我可以单独选择选择列表但不能创建多个选项。
这是什么原因以及我该怎么办?
JS:
$.ajax({
type: "GET",
url: "core/spine.php",
data: [...]
cache: false,
success: function (data) {
data = JSON.parse(data);
$.each(data.response, function(key, value) {
$('#orderMultipleList')
.append($("<option></option>")
.attr("value",value)
.text(value));
});
HTML:
<select name="orderMultipleList[]" class="form-control"
multiple required></select>
JSON数据响应:
{"response":["2005","2006","2007","2008","2009","2010","2011","2012","2013","2014","2015","2016","2017","2018"]}
结果:
没有。
与工作代码:
<select name="orderMultipleList" class="form-control"
required></select>
与不工作代码:
<select name="orderMultipleList[]" class="form-control"
multiple required></select>
你需要像这样添加一个id
<select name="orderMultipleList[]" id = "orderMultipleList" class="form-control"
multiple required></select>
因为
$('#orderMultipleList')
需要id,而不是名字