1. 程式人生 > >解決 html input file onchang 事件觸發一次後失效問題

解決 html input file onchang 事件觸發一次後失效問題

JS:
$(function(){
    $("#userFile").change(function(){
        batchImportUser();
    });
})
function batchImportUser(){
    alert(1);				
    $("#userFile").replaceWith('<input style="opacity: 0;z-index:9999999;position: relative;left: -145px;" id="userFile" name="file" type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" value="匯入使用者" class="sureBtn sureBtnEx marginL20"/>');  
    $("#userFile").on("change", function(){  
        batchImportUser();
    });  
}
$("#userFile").replaceWith('<input style="opacity: 0;z-index:9999999;position: relative;left: -145px;" id="userFile" name="file" type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" value="匯入使用者" class="sureBtn sureBtnEx marginL20"/>');   $("#userFile").on("change", function(){   batchImportUser(); });   }
HTML:
<input style="opacity: 1;z-index:9999999;position: relative;left: -145px;" id="userFile" name="file" type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" value="匯入使用者" class="sureBtn sureBtnEx marginL20"/>