我希望在标记中有这样的结果:
<div class="span4 messageField">
<span id="messagefield">Message 1</span>'
<span id="messagefield">Message 2</span>'
<span id="messagefield">Message 3</span>'
<span id="messagefield">Message 4</span>'
<span id="messagefield">Message 5</span>'
</div>
我已经使用jquery将第一个span消息字段附加到我的div:
$('.messageField').prepend('<span id="messagefield"></span>');
以下是生成messagefield文本的click函数:
$("#fireCreate").click(function(e) {
$("#messagefield").html("Importerar titelsida, vänta ...");
});
这是html中的标记:
<div class="span4 messageField">
<!-- HERE IS WHERE THE SPANS WILL STACK UP -->
</div>
答案 0 :(得分:1)
你可以做到
//the counter is here just to show you that this works, you could use this to generate an id
var counter = 0;
$("#fireCreate").click(function(e) {
counter++;
if($('.messageField span').length === 5){
$('.messageField span:last').remove();
}
$('.messageField').prepend($('<span />', { id: "message"+counter, class: "singleMessage", text : "Importerar titelsida, vänta ..."+counter}));
});