![](/img/trans.png)
[英]get the multiple selection as comma separated from select box into a text input
[英]How to create comma seperated value in javascript on selection of values from multiple selection select box?
我需要從multiselect select框中選擇的值作為相對應的值,以便我可以在AJAX調用中使用這些值來使用這些值從db表中獲取數據。
請幫助我。
謝謝
假設multiSelect
是select DOM對象(例如,由document.getElementById
獲得),那么resultString
將是您要查找的字符串。
var resultArray = [];
for(var i=0; i < multiSelect.options.length; i++) {
if (multiSelect.options[i].selected) {
resultArray.push(multiSelect.options[i].value);
}
}
var resultString = resultArray.join(",");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.