发生的情况是,一旦您单击图例,其内容就会被新图例替换;但是当你点击它时,新的不会调用它的点击处理程序!
这是 js Fiddle 的链接:http: //jsfiddle.net/CfkKk/2/
HTML:
<fieldset class="MyClass">
<legend class="MyClass">
My Class (click on me)
</legend>
</fieldset>
CSS:
legend.MyClass:hover {
cursor: pointer;
color: blue;
}
legend.MyNewClass:hover {
cursor: pointer;
color: blue;
}
JS:
$('legend.MyClass').click(function() {
var fieldset = $('fieldset.MyClass');
var legend = fieldset.find('legend');
var newLegend = "<legend class=\"MyNewClass\""
+ "<h3>My New Class (click on me again)</h3>"
+ "</legend>";
legend.replaceWith(newLegend);
});
$('legend.MyNewClass').click(function() {
alert('this is a new class');
});