我尝试将每个数组项包装在 <li></li>
中并保存到变量中。
之后插入<ul>
在开头和 </ul>
在最后。
到目前为止我所得到的:
$("document").ready(function() {
var array = ["one", "two", "three", "four", "five"];
jQuery.each(array, function(index, value) {
value[index].wrap("<li></li>");
var listItems = value[index].join("\n");
});
});
但我收到此错误:
value[index].wrap is not a function
最佳答案
更新了你的 fiddle : https://jsfiddle.net/vkq3hnzu/2/
var array = ["one", "two", "three", "four", "five"],
ul = $('<ul>');
jQuery.each(array, function(index, value) {
$('<li>').text(value).appendTo(ul);
});
ul.appendTo('body');
关于javascript - jQuery 包装每个数组项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43791566/