我正在使用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