如何在单击提交输入时从输入同级中删除属性“已禁用”

时间:2010-10-07 08:58:32

标签: javascript jquery

我有这个问题:我需要从提交输入的兄弟输入中删除“禁用”属性。这是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>

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

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

但我不行。

有什么建议吗?

5 个答案:

答案 0 :(得分:5)

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

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

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

使用.attr('disabled', false)也应该可行,并且可以更可靠。

答案 1 :(得分:1)

侨,

你试过.prevAll()吗?

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

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

注意:这是一个对象,而不是字符串文字(你写'this')

答案 2 :(得分:0)

只需删除此处的引号即可。

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

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

的值

答案 3 :(得分:0)

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

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

请查看此链接JQuery Sibling

答案 4 :(得分:0)

试试这个:

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