如何在div中包装循环?

时间:2017-05-09 04:13:36

标签: javascript jquery html

我一直坚持这个愚蠢的事情,我无法弄清楚如何在div中包装我的for循环。

for (item = 0; item < event.length; item++) {
        var ID = event[item].id;
        element.find(".title").after("<span class='id'><img src='/avatar/" +ID+ "'/></span>");
        }

我希望得到这个:

<div>
<span></span>
<span></span>
<span></span>
</div>

任何帮助都很适合。

2 个答案:

答案 0 :(得分:2)

希望此代码段有用

def appendRecords(record, oldRecord):
    # Check to guard against empty lines in the input csv file
    if len(record):
        oldRecord[-1] = oldRecord[-1] + ' ' + record[0]
        record.pop(0)
        oldRecord.extend(record)



with open(fileIn, "rb") as input:
    with open(fileOut,'wb') as output:
        w = csv.writer(output, delimiter='|',quoting=csv.QUOTE_NONE,quotechar='')
        oldRecord = None
        for record in csv.reader(input, delimiter='|',quoting=csv.QUOTE_NONE):
            if oldRecord is not None:
                appendRecords(record, oldRecord)
                record = oldRecord

            if record[-1].endswith('"'):
                print([s[1:-1] for s in record])
                w.writerow([s[1:-1] for s in record])
                oldRecord = None
            else:
                oldRecord = record

答案 1 :(得分:0)

$(document).ready(function() {  
//Assume sample event array 
var event = [1, 2, 3];
for (item = 0; item < event.length; item++) {
    var ID = event[item];
    $("<span class='id'><img src='/avatar/" +ID+ "'/></span<br>").appendTo('#name');
  };
});

考虑下面的示例HTML

<div id="name">
   hello
</div>

这样您就可以在div中填充内容