之前是
var str="";
str += "<div></div>";
$(".box").append(str);
新学一招~
var $temp;
$temp = $('<div></div>');
$(".box").append($temp);
js实例:
<script>
picBox(3, '100px', '100px', [1,2,3,4,5,6,7], $('.container'), 1);
function picBox(n, _hei, _wei, data, $target, rel) {
for (var j = 0; j < data.length / n; j++) {
var $temp = $temp + j;
$temp = $('<div></div>');
for (var i = 0 + j * n; i < n + j * n; i++) {
if (data.length > i) {
var $imgsmall = $('<a class="i_border" rel="' + rel + '" href="javascript:;" target="_blank"><div class="smallbox e_img"></div></a>');
$imgsmall.find(".smallbox").css({ "height": _hei, "width": _wei, "background": "pink", "background-size": "cover" })
$temp.append($imgsmall);
}
}
$target.append($temp);
}
}
</script>
css:
<style>
.container>div{
margin:5px;
border:1px solid #666;
}
.container a{
display:inline-block;
border:1px solid #999;
margin:10px;
}
</style>