admin管理员组文章数量:1390784
I have these dynamically created file input HTML elements which are used with a jQuery-ajax file upload plug-in.
I would like the file upload to start after the input value has been updated. However, Internet Explorer seems to ignore the Javascript onChange.
How can I achieve this in IE?
Example:
var html = $('<div class="add_input">'+
'<input type="file" name="file"/></div>').change(submit);
$('#add_inputs').prepend(html);
I have these dynamically created file input HTML elements which are used with a jQuery-ajax file upload plug-in.
I would like the file upload to start after the input value has been updated. However, Internet Explorer seems to ignore the Javascript onChange.
How can I achieve this in IE?
Example:
var html = $('<div class="add_input">'+
'<input type="file" name="file"/></div>').change(submit);
$('#add_inputs').prepend(html);
Share
Improve this question
edited Oct 20, 2012 at 19:01
mjc
asked Nov 23, 2009 at 0:46
mjcmjc
3,4363 gold badges37 silver badges47 bronze badges
2 Answers
Reset to default 4You could just replace the above with something along these lines
var html = $('<div class="add_input"><input type="file" name="file"/></div>');
$('#add_inputs').prepend(html);
$("div.add_input > input[name='file']").change(submit);
or
var html = $('<div class="add_input"><input id="filer" type="file" name="file"/></div>');
$('#add_inputs').prepend(html);
$("#filer").change(submit);
When you create elements from HTML in jQuery, the returned handle references the outermost element(s), so you're putting the change
event handler on the <div>
, not the <input>
.
This works nonetheless in most browsers because in the DOM Level 2 Events specification, the change
event ‘bubbles’ up the document to inform its parents when it changes, so an event handler on <div>
will get informed of any changes on any of its child <input>
s. However IE has its own event model in which change does not bubble.
An alternative:
($('<input type="file" name="file" />')
.change(submit)
.prependTo('#add_inputs')
.wrap('<div class="add_input"></div>')
);
本文标签: javascriptInternet Explorer file input onchangeStack Overflow
版权声明:本文标题:javascript - Internet Explorer file input onchange - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744754331a2623369.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论