[英]Using keyup to remove class from dynamically create buttons
I have some buttons that are dynamically created. 我有一些动态创建的按钮。 When they are pressed, the .disabled
class is added to them and the text()
is entered into an input field. 当按下它们时,将.disabled
添加.disabled
类,并将text()
输入到输入字段中。 I want to remove the disabled
class when the input field is empty. 我想在输入字段为空时删除disabled
类。 I am checking this on the keyup. 我正在检查这个keyup。 I have not been successful in doing this and would like some help. 我没有成功完成此操作,希望获得帮助。
Here is my jQuery: 这是我的jQuery:
Binded event: $languageInput.on('keyup', _resetLanguageTags)
绑定事件: $languageInput.on('keyup', _resetLanguageTags)
Function: 功能:
function _resetLanguageTags(){
if($(this).val() == ''){
console.log('empty');
$('button').each(function(){
$(this).removeClass('disabled');
});
}
}
As you can see, I have a console.log('empty');
如您所见,我有一个console.log('empty');
to make sure that the input is empty and it is working when the input is, in fact, empty. 确保输入为空并且实际上在输入为空时可以正常工作。
I this this example will help using the disabled property : 我这个例子将有助于使用disabled属性:
<button disabled>a</button>
And remove disabled with: 并通过以下方式删除禁用的内容:
$(this).prop('disabled', false);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.