动态添加dom,和对应的删除事件
<div class="TextCon"></div>
//全局
var zhj_global_params = {
geneNum : 0,
getGeneNumFn :function(){
return this.geneNum ++;
}
}
var textDom = '<div class="content" id = "zhaDyDiv_zj@zhjGeneNum@">\n'+
'<p>内容</p>\n'+
'<a href="#" data="zj@zhjGeneNum@">shanchu</a>\n'+
'</div>'
//点击添加按钮
$('#addBtn').on('click',function(){
var reg = /zj@zhjGeneNum@/g;
var textDomAppend = textDom,replace(reg,zhj_global_params.getGeneNumFn())
$('.TextCon').append(textDomAppend);
})
$('.TextCon').on('click','a',function(){ //绑定事件
$('#zhjDyDiv_' + $(this).attr('data')).remove();
})