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/
精彩评论