[英]Cannot disable button in javascript after AJAX call
我有以下js文件,我想在AJAX調用后禁用按鈕:
$('document').ready(function() {
const runField = $('input[id=run]')
const runButton = $('.btn-run')
const saveButton = $('.btn-save')
runButton.on('click', function(event) {
console.log('run clicked')
runField.val(1)
event.preventDefault()
$('.btn-run').prop('disabled', true)
console.log($('.btn-run').prop('disabled'))
runCode()
$('.btn-run').prop('disabled', false)
})
})
runCode()
是我的AJAX函數,但是當我使用.prop('disabled', true)
,即使下面的日志行在控制台中返回true,該按鈕仍未被禁用。 我確保所有屬性(例如ID)都是正確的。 任何幫助表示贊賞!
您需要為$('.btn-run').prop('disabled', false)
runCode
或回調函數-如果可能,共享runCode
會有所幫助。
您的AJAX回調應如下所示。 URL將有所不同,但是$('.btn-run').prop('disabled', false)
成功運行。 這意味着它將生效。
$.ajax({
url: "demo_test.txt",
success: function(result){
$('.btn-run').prop('disabled', false)
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.