javascript 单击提交输入时如何从输入兄弟姐妹中删除属性“已禁用”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3880118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 02:32:39  来源:igfitidea点击:

How to remove the attribute "disabled" from input siblings when i click on a submit input

javascriptjquery

提问by Nicola Peluchetti

i have this problem: i need to remove the "disabled" attibute from the siblings inputs of submit input. Here is the html:

我有这个问题:我需要从提交输入的兄弟输入中删除“禁用”属性。这是html:

<td>
<input type="hidden" value="2000000000002_STATUTO_07_10_2010.gif" name="nomeDocumento" disabled="true">
<input type="hidden" value="811ecdd0-65e9-49d6-8d9d-8b7c9d9b6407" name="UUID" disabled="true">   
<input type="submit" value="cancella" name="cancella">
</td>

i need a simple way using jquery to remove the disable attribute when i click on the submit. I tried:

当我单击提交时,我需要一种使用 jquery 的简单方法来删除禁用属性。我试过:

$('input[name=cancella]').click(function(){
$('this').prev().removeAttr('disabled');
$('this').prev().prev().removeAttr('disabled');
}

But i doesn't work.

但我不工作。

Any suggestion?

有什么建议吗?

回答by BGerrissen

$('input[name=cancella]').click(function(){
   $(this)
      .closest('td')
      .find('input[name!='+this.name+']')
      .attr('disabled', false);
});

Fabrizio Calderan .prevAll()way is better. However, .siblings()could be even better, so it doesn't matter where the siblings are.

Fabrizio Calderan.prevAll()方式更好。然而,.siblings()可能会更好,所以兄弟姐妹在哪里并不重要。

$('input[name=cancella]').click(function(){
   $(this).siblings('input').attr('disabled', false);
});

Using .attr('disabled', false)should work as well and could be more reliable.

使用也.attr('disabled', false)应该有效,并且可能更可靠。

回答by Nicola Peluchetti

Ciao,

再见,

have you tried .prevAll() ?

你试过 .prevAll() 吗?

$('input[name=cancella]').click(function(){
  $(this).prevAll().removeAttr('disabled');
}

http://api.jquery.com/prevAll/

http://api.jquery.com/prevAll/

Note: this is an object, not a string literal (you wrote 'this')

注意:这是一个对象,而不是字符串文字(您写的是“this”)

回答by Chinmayee G

Simply remove quotes around this i.e.

只需删除围绕这个 ie 的引号

$('input[name=cancella]').click(function(){
    $(this).prev().removeAttr('disabled');
    $(this).prev().prev().removeAttr('disabled');
}

this is your object not value for attribute [name/id]

这是您的对象,而不是属性 [name/id] 的值

回答by dmarucco

You can use the .siblings()traversing method:

您可以使用.siblings()遍历方法:

$('input[name=cancella]').siblings().removeAttr('disabled');

Have a look at this link JQuery Sibling

看看这个链接JQuery Sibling

回答by Joel Harris

Try this:

试试这个:

$('input[name=cancella]').click(function(){
  $(this).siblings().removeAttr('disabled');
}