我正在使用replaceWith for input type=file
来处理用户想要上传的文件的更改。jquery replaceWith暗示
我有这样的代码:
$('#add_cv_input').change(function() {
// here is some code
else {
alert('put one of this: pdf doc docx');
$("#add_cv_input").replaceWith('<input id="add_cv_input" type="file"/>');
}
});
现在的问题是,这个jQuery改变事件不被第一次用户已经上传了错误后延调用。
我不知道为什么会发生这种情况。如果用户第一次上传有效的扩展名,然后将其更改为其他有效的扩展名,则一切正常。
如何在销毁元素后重新安装事件? – vlio20
@VladIoffe - 我添加了如何重新安装到我的答案。 – jfriend00
你确定它是这样的:$('#add_cv_input')。change(processChange);而不是这样:$('#add_cv_input')。change(processChange());? – vlio20