开发者

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

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

<td>
<input type="hidden" value="2000000000002_STATUTO_07_10_2010.gif" name="nomeDocumen开发者_如何学Goto" 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:

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

But i doesn't work.

Any suggestion?


$('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.

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

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


Ciao,

have you tried .prevAll() ?

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

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

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


Simply remove quotes around this i.e.

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

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


You can use the .siblings() traversing method:

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

Have a look at this link JQuery Sibling


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜