[英]jquery use html () after setting the content, how to make the new elements event and original elements bind the same event?
HTML: HTML:
<div id="1">
<div>
<ul>
<li><button id="button">a</button></li>
<li><span>1</span></li>
</ul>
</div>
</div>
<div id="2">
<ul>
<li></li>
</ul>
</div>
JQUERY: JQUERY:
$("#button").live("click",function(){
var s = Number($(this).parents("ul").find("span").text());
$(this).parents("ul").find("span").text(s+1);
$("#2 li").html($("#1 li").html());
});
The problem is that when I click on the button , span's number add number 1 and DIV#2 set up a new button , how can i add DIV#1 span number when i click DIV#2 new , I means how this function can find the right parents and span? 问题是,当我单击按钮时,跨度的数字加1并DIV#2设置了一个新按钮,当我单击DIV#2新建时,如何添加DIV#1跨度号,我的意思是该函数可以找到合适的父母和跨度?
i want to add number 1 when i click new button ,that's all,thanks! 我想在单击新按钮时添加数字1,就这样,谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.