我有一个数组:
arr = ['a', 'b', 'c', ... ]
Run Code Online (Sandbox Code Playgroud)
我希望它是:
<div>
<ul>
<li>a
<li>b
<li>c
...
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
所以我正在尝试:
$('div').append('<ul>');
$.each(arr, function () {
$('div').append('<li>' + this);
});
$('div').append('</ul>');
Run Code Online (Sandbox Code Playgroud)
但似乎没有工作......我怎么排队这个?
也许你想要的
$('div').append('<ul></ul>');
$.each(arr, function () {
$('ul').append('<li>' + this);
});
Run Code Online (Sandbox Code Playgroud)