开发者

jQuery insert file input onChange error

开发者 https://www.devze.com 2023-03-29 17:57 出处:网络
I have the following code: HTML <label>File Upload: </label> <input type=\"file\" name=\"file[]\" />

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

精彩评论

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