开发者

Clone element with events in JavaScript

I have an element:

<input type="file" id="fileUpload" size="100" name="fileUpload"/>

A change event is bound to this element i.e. :

$('input[type=file]').change(f开发者_StackOverflow中文版unction()
{
alert('changed');
});

I am cloning this element using:

var newElement = $('#fileUpload').clone();

and appending newElement to the form:

$('form').append(newElement);

Now what happens is that after appending the change event is not bound to the new element. Any idea why this is and how to solve this?


var newElement = $('#fileUpload').clone(true);

jQuery clone

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜