我有一个值为 'a|mike||c|John||d|Pierre' 的变量
(a、b 和 c 是 guid 而不是真正的字母)
现在我想用 id 'officers' 填充一个 html select 元素,选项以 'a' 作为值,名称作为文本。
我坚持使用 | 上的拆分、数组和 jquery 来填充列表....
最佳答案
var outer = myString.split('||');
var select = $('<select></select>');
var options = '';
for(var i = 0; i < outer.length; i++)
{
var inner = outer[i].split('|')
options += '<option value="' + inner[0] + '">' + inner[1]+ '</option>';
}
select.html(options);
关于javascript - 使用管道符号分隔数据中的 jquery 填充 html 选择框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5894633/