<body><table id="tab"></table></body>
<script>
var tList= ['Windows','Ubuntu14.04','CentOS 7.2'];
var htmlStr='';
$.each(tList,function(i){
var type=
tList[i].indexOf('Windows') >= 0 ?'Windows'//字符中如果包含windows
: tList[i].indexOf('Ubuntu') >= 0 ?'Ubuntu'//字符中如果包含Ubuntu
: tList[i].indexOf('CentOS') >= 0 ?'CentOS'//字符中如果包含CentOS
: '';
htmlStr+='<tr><td><i class="'+type+
'_img"><i/></td><td>'+tList[i]+'</td></tr>';
})
$('#tab').append(htmlStr);
</script>
追问您好,您这个代码可以给我解释下么?我是个初学者,好多不太懂,而且我想要的代码格式是windows2008。大概就是这样
追答<body><table id="tab"></table></body>
<script>
//获取你的后台数据,我这里写死了一个数组
var tList= ['Windows','Ubuntu14.04','CentOS 7.2'];
var htmlStr='';
//循环数组
$.each(tList,function(i){
var type=
tList[i].indexOf('Windows') >= 0 ? 'Windows' //字符中如果包含windows
: tList[i].indexOf('Ubuntu') >= 0 ? 'Ubuntu' //字符中如果包含Ubuntu
: tList[i].indexOf('CentOS') >= 0 ? 'CentOS' //字符中如果包含CentOS
: '';
//html代码拼接(已经改成你想要的效果)
htmlStr+='<tr><td><i class="'+type+'_img"><i/>'+tList[i]+'</td></tr>';
})
$('#tab').append(htmlStr); //插入到table里
</script>