jQuery -如何在元素启用时触发一个函数

jQuery - how to trigger a function whenever a element enabled?

本文关键字:函数 一个 启用 元素 jQuery      更新时间:2023-09-26

我希望修复我的功能工作,每当元素启用。目前它不起作用。

这是我的尝试:

var x = function () {
    input = $('#username');
    if (input.prop('disabled')) {
        console.log('i am enabled'); //  how to trigger this?
    }
}
x();
$('#enable').on('click', function(){
    $('#username').removeAttr('disabled');
})

现场演示注意:我的应用程序总是删除属性disabled

我已经创建了一个小提琴(修改你的小提琴)希望这是你需要的解决方案

小提琴

代码片段:

if (typeof attr !== 'undefined' && attr !== false) {
    console.log('i am disabled'); //  how to trigger this?
}