有谁能告诉我声明有什么问题。插入分号作为文本/字符串的格式是否正确?
const cardList=["diamond", "fpaper-plane-o", "anchor","bolt","cube","anchor","leaf","bicycle","diamond","bomb","leaf","bomb","bolt","bicycle","paper-plane-o","cube"];
for( let i=0; i<=length; i++){
jQuery('.deck')('<li class="card"><i class="fa fa-' + cardList[i] + '"></i></li>');
}
答案 0 :(得分:1)
这是语法错误:
jQuery('.deck')('<li class="card"><i class="fa fa-' + cardList[i] + '"></i></li>');
//------------^^
您必须在此处使用.append()
功能:
jQuery('.deck').append('<li class="card"><i class="fa fa-' + cardList[i] + '"></i></li>');
<强>段强>
const cardList = ["diamond", "paper-plane-o", "anchor", "bolt", "cube", "anchor", "leaf", "bicycle", "diamond", "bomb", "leaf", "bomb", "bolt", "bicycle", "paper-plane-o", "cube"];
for (let i = 0; i < cardList.length; i++) {
jQuery('.deck').append('<li class="card"><i class="fa fa-' + cardList[i] + '"></i></li>');
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="deck"></ul>
更多更改:
for
循环变量和条件错误。