我看过几个关于这个主题的帖子,但完全没有得到答案。我有一个 onClick 事件,它调用 Uploadfile() 函数,只有在调用 Uploadfile() 函数之后,我才希望调用 EnableSaveButton() 函数。下面粘贴的是代码,我有点击事件、Uploadfile() 函数和 EnableSaveButton() 函数。目前仅调用 Uploadfile(),但不会触发 EnableSavebutton() 函数。如果有人能告诉我我做错了什么,将不胜感激。
***更新:让我重新表述一下这个问题。如何确保仅在调用 UploadFile() 之后才调用 EnableSaveButton()。目前发生的情况是,EnableSaveButton 在 UploadFile() 之前触发。
$("#btnUploadFile").click(function(event) {
event.preventDefault();
uploadFile();
EnableSaveButton();
});
function uploadFile() {
$.get('<%: Url.Action("UploadFile","Files") %>', null, function(getData) {
$(getData).appendTo('body');
});
}
function EnableSaveButton() {
var selectedvalue = $("#FileGuid").val();
alert(selectedvalue);
if (selectedvalue != "") {
$("#btnSave").removeAttr("disabled");
}
}
最佳答案
function (event) {
event.preventDefault();
EnableSaveButton();
}
此函数已声明但未分配或使用...因此未调用您的函数 EnableSaveButton
。
关于javascript - javascript 中的事件顺序无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12163352/