怎么根据人数制作盒子
我也踩过这个坑( 1 )
本地储存
详细描述
截图
代码
编辑于2024-11-23
-
[北京|结业弟子]JS-张新0
var a = 0;
var c = 1;
var x = '';
for (a = 0; a < num; a++) {
c = a + 1;
x = '<div class="player">' +
'<div class="p-top">' +
identifyIfo[a] +
'</div>' +
'<div class="p-down">' +
c +
'号' +
'</div>' +
'</div>';
$('#player-box').append(x);
}<div id="player-box">
</div>根据身份数组传过来的人数,在js中添加盒子
编辑于2018-11-05 -
[成都|结业弟子]JS-董家宇0
根据你传过来的人数,遍历动态渲染出盒子
<ul><li><strong>杀手</strong><span>1</span></li></ul>
for (i = 0; i < arr.length; i++) {var inBox ='<li>\n' +'<strong>\n' + arr[i] +'</strong>\n' +'<span>\n' + (i + 1) + "号" +'</span>\n' +'</li>';$('ul').append(inBox);}编辑于2019-05-17 -
[真传弟子]JS-张林骞0$(function () { // 动态生成玩家var identity = undefined;var empty = undefined;for (var i = 0; i < rgl; i++) { //rgl 玩家数量identity = reordering[i].name;if(reordering[i].name === '平民'){ //判断是平民civiliansNumber++} else if (reordering[i].name === '杀手'){ //判断是杀手killerNumber++};if( killer[i].state === '1' ){empty = '';} else if (killer[i].state === '0'){empty = 'content-color';};var box = '<div class="content-items ' + empty + '" id="box-'+[i]+'">' +'<div>' +'<div>' +'<p>' + identity + '</p>' +'<p>' + (i + 1) + '号' + '</p>' +'</div>' +'<div>' +'<img src="../image/刀.png" width="25px">' +'</div>' +'</div>' +'</div>'$('.content').append(box); // 通过 append 添加盒子};var kNumber = sessionStorage.getItem("killerNumber");var cNumber = sessionStorage.getItem("civiliansNumber");if ( kNumber !== null && cNumber !== null){killerNumber = Number (kNumber) // 杀手 人数civiliansNumber = Number(cNumber) // 平民 人数};});编辑于2019-08-17
- 去第 页