[英]jQuery .val() on multiple select, don't comma separate?
我有一个多选:
<select id="filter-cardset" data-placeholder="Select a Card Set" multiple="multiple">
<option>Metal Raiders</option>
<option>Abyss Rising</option>
<option>Shonen, Vol 1</option>
<option>Shonen, Vol2</option>
</select>
我使用 jQuery 来获取值:
var selection = jQuery("#filter-cardset").val();
结果是这样的数组:
["Metal Raiders", "Shonen, Vol2"]
然后我将其发送到 API:
myapi.com/info.php?selection=Metal Raiders, Shonen, Vol2
发送方式如下:
if(selection !=""){ apiurl+= "&selection="+encodeURIComponent(selection); }
如您所见,问题在于选项值中的逗号。 我的 API 可以用“;”分隔它们象征。
metal raiders;shonen,vol2
但是我似乎无法通过 URL 发送它,因为它总是用逗号分隔值。 任何的想法?
基于 API 接受的模式做:
var selection = jQuery("#filter-cardset").val().join(';');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.