次の例を見てください。
$.fn.foo = function() {
var $input = $('<input type="text"/>');
var $button_one = $('<button>One</button>');
var $button_two = $('<button>Two</button>');
$button_one.click(function(){
$input.val('hey');
});
$button_two.click(function(){
$input.replaceWith( $input.val('').clone( true ) );
});
this.append( $input, $button_one, $button_two );
};
デモを確認してください: http://jsbin.com/ezexah/1/edit
ここで「one」をクリックすると、入力に「hey」が表示されます。次に「2」をクリックしてから、もう一度「1」をクリックしても機能しません。true
オプションを使用してclone
すべてのイベントをコピーしても、まだ機能しません。何か案は?