【发布时间】:2015-10-15 09:52:03
【问题描述】:
我将更改事件附加到动态呈现的表单字段,如下所示:
var html ='';
html += '<div class="Gallery-overlayContentWrapper">';
html += '<center>';
html += '<h3>'+self.data('uploadHeading')+'</h3>'
html += parent;
html += '<form id="Gallery-uploadForm" enctype="multipart/form-data" method="post">';
html += '<input type="hidden" name="Gallery-Parent" id="Gallery-Parent" value="'+self.data('activeFolder')+'" />';
html += '<p><input type="file" name="file1" id="file1"></p>';
html += '<p><progress id="Gallery-uploadProgress" value="0" max="100"></progress></p>';
html += '</form>';
html += '</center>';
html += '</div>';
$(self).find(".Gallery-"+self.data('overlayType')).append(html);
$(self).find(".Gallery-"+self.data('overlayType')).fadeIn(); //This only covers the thumbs area
setTimeout(function(){
$(self).find('#file1').change(function(){
self.data('uploadFile')(self);
});
},1000);
这行得通,但是像这样依赖 1 秒后渲染的元素感觉很糟糕,有没有更清洁的方法来做到这一点?
【问题讨论】:
-
委托不会对资源要求更高,只要有任何事情触发我的页面发生更改,浏览器就会查找事件?
标签: javascript jquery html timeout