【注意】最后更新于 5年前,文中内容可能已过时,请谨慎使用。
问题描述
使用原生js+bootstrap+jquery想实现vue v-for功能去循环生成一个块,发现无从下手,现在记录一下解决方案
解决方案
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>
<ul id="container"></ul>
<script>
var htmlSeg = []
for(var i=0;i<10;i++) {
htmlSeg.push('<li class="cls ls hdl-details" data-id="idx ' + i + '">' + i + '</li>')
}
$('#container').html(htmlSeg.join(''))
$('.hdl-details').click(function(i){
console.log($(this).data('id'))
})
</script>
</body>
</html>
|