开发者

How can I remove an attribute with jQuery?

开发者 https://www.devze.com 2022-12-12 12:38 出处:网络
I can\'t seem to get removeAttr to work, I\'m using the example I saw on the jQuery site. Basically onclick I add the attribute to disable a field (which works just fine) but when the user clicks agai

I can't seem to get removeAttr to work, I'm using the example I saw on the jQuery site. Basically onclick I add the attribute to disable a field (which works just fine) but when the user clicks again it should enable the field in question. I use开发者_开发知识库d alerts to make sure the else block is being fired, so I know that's not it.

Code:

$('#WindowOpen').click(function (event) {
  event.preventDefault();
  $('#forgot_pw').slideToggle(600);

  if('#forgot_pw') {
    $('#login_uname, #login_pass').attr('disabled','disabled');
  } else {
    $('#login_uname, #login_pass').removeAttr('disabled');
  }
});

Thanks.


All good used this:

$('#WindowOpen').toggle(
    function()
    {
        $('#login_uname, #login_pass').attr("disabled","disabled");     
    },
    function()
    {
        $('#login_uname, #login_pass').removeAttr("disabled");      
    });


Your problem is that the following line of code will always evaluate to true.

if('#forgot_pw')

try replacing with

if($('#forgot_pw').attr('disabled'))


$('#forgot_pw').attr('disabled', false);

should work for you.

0

精彩评论

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

关注公众号