Цикл с ума сходит
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script>
var arr = [['1'],['2'],['3']];
$('.lead ul').html(function(){
arr.forEach(function(n, i) {
var lead = '<li><p>'+arr[i][0]+'</p></li>';
return lead;
});
});
</script>
<div class="lead">
<ul>
</ul>
</div>
</body>
</html>
Ребят, подскажите, что тут не так? Почему-то не дублируется 1,2,3:) |
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<div class="lead">
<ul>
</ul>
</div>
<script>
var arr = [['1'],['2'],['3']];
arr.forEach(function(ar){
$('.lead ul').append('<li><p>'+ar[0]+'</p></li>');
});
</script>
</body>
</html>
|
Ramzes94,
хотябы из за того что элементов к которым пытается обращаться скрипт еще нет. |
Цитата:
Цитата:
|
Ramzes94,
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script>
$(function() {
var arr = [['1'],['2'],['3']];
$('.lead ul').html(function(){
return arr.map(function(n) {
return '<li>'+n+'</li>';
});
});
});
</script>
<div class="lead">
<ul>
</ul>
</div>
</body>
</html>
|
Вот то что надо, спасибо:)
|
А как Вам карму прибавить? :)
|
Подскажи, вот сделал, а что если несколько значений в массиве, например [[1,2,3],[1,2,3],[1,2,3]]
|
Ramzes94,
и что в итоге ? |
Ramzes94,
какой результат нужен? html сделайте. |
| Часовой пояс GMT +3, время: 22:56. |