[英]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.