开发者

jQuery insert file input onChange error

I have the following code:

HTML

<label>File Upload: </label>
<input type="file" name="file[]" />
开发者_开发问答

jQuery

$('#property_enquiry input[type=file]').change(function() {
    $('<input type="file" name="file[]">').insertAfter("input[type=file]");
});

What I want to happen is once the first file is added a new input is added underneath the current one. The above code works when adding the first file to create a second input, however when adding a second file a third input isn't created.


Try this:

$('#property_enquiry input[type=file]').live('change', function() {
    $('<input type="file" name="file[]">').insertAfter("input[type=file]:last");
});

This will automatically work with newly added file inputs.

Try it here: http://jsfiddle.net/Lgmcz/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜