我正在尝试应用 .each 方法,以便此页面上的每个“响应文本区域”都是单独的目标(我在一个页面上有多个表单提交,并且我希望在每一个,直到您在相应的文本区域中输入文本)。但我不知道该把它扔到哪里。我可以链接方法吗?
(这一切都在文档中。准备好)
$('.submit').attr('disabled', 'disabled');
$('.response-text-area').each.keyup(function() {
if ($('.response-text-area').val() == "") {
$('.submit').attr('disabled', 'disabled');
}
else {
$('.submit').removeAttr('disabled');
}
});
最佳答案
只需删除 .each
(whos 语法无论如何都是不正确的)。该事件将绑定(bind)到具有 response-text-area
类的每个控件。
$('.response-text-area').keyup(function(){
if($(this).val() == ""){
// I'd need to see your markup to provide code here.
// You need to find the correct submit button in relationship
// to the current item. Something similar to this:
$(this).parent().find('.submit').attr('disabled', 'disabled');
}
else{
$(this).parent().find('.submit').removeAttr('disabled');
}
})
关于jquery - 如何将jquery函数应用到每个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9889981/