这对于专家来说似乎很容易,
但是,我该如何转换下拉列表(选择框)的内容并将它们存储到逗号分隔的变量中?
[DROP DOWN]
abdcef1
ghijklm2
nopqrs3
tuvwx4
yz0007
预期结果:
var x = abdcef1,ghijklm2,nopqrs3,tuvwx4,yz0007
非常感谢和感谢您的所有帮助和支持。
干杯,
杰伊
最佳答案
尝试:
<script>
function getSelectedValues() {
var result = "";
var mysel = document.getElementById("myselect");
for (var i = 0; i < mysel.options.length ; i++) {
result = result + mysel.options[i].text + ",";
}
result = result.substring(0,result.length-1);
return result;
}</script>
哪里
<select id="myselect">
<option value="abdcef1">abdcef1</option>
<option value="ghijklm2">ghijklm2</option>
<option value="nopqrs3">nopqrs3</option>
<option value="tuvwx4">tuvwx4</option>
<option value="yz0007">yz0007</option>
</select>
关于javascript - 转换下拉框的内容并将其存储在变量中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14510856/