当我使用replaceWith
将一个元素从DOM中移出,然后再将其replaceWith
回去时,绑定在它上面的事件不会触发。 我需要事件保持完整。
Here s my Javascript:
var replacement = $(document.createElement( span ));
var original = $(this).replaceWith(replacement);
replacement
.css( background-color , green )
.text( replacement for + $(this).text())
.click(function() {
replacement.replaceWith(original);
});
In the demo, when you click an element, it is replaced with another element using replaceWith
. When you click the new element, that is replaced with the original element using replaceWith
. However, the click handler does not work any more (where I would think it should).