【发布时间】:2019-06-19 08:12:50
【问题描述】:
我正在尝试将 select2 数组转换为要在表单中使用的字符串。目前我的输出如下所示:
?source%5B%5D=x1&source%5B%5D=x2
我希望将其转换为以逗号分隔的字符串。我尝试使用'string = source.join()',但我的字符串输出为空。
%5B%5D=x1&source%5B%5D=x2&string=
我想要得到的是这样的:
字符串%5B%5D=x1,x2
<form action="/action_page.php">
<select class="form-control select2" multiple="" id="source" name="source[]" style="width: 250px;">
<optgroup label="Group1">
<option>x1</option>
<option>x2</option></optgroup>
<optgroup label="Group2">
<option>y1</option>
<option>y2</option></optgroup>
</select>
<script type="text/javascript">
$(".select2").select2({
tags: true
});
</script>
<script type="text/javascript">
string = source.join()
</script>
<input type='hidden' name='string' ></input>
<br><br>
<input type="submit">
</form>
【问题讨论】:
标签: javascript html jquery-select2