jQuery删除属性 [英] jQuery remove attribute

查看:18
本文介绍了jQuery删除属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法让 removeAttr 工作,我正在使用我在 jQuery 网站上看到的示例.基本上 onclick 我添加属性来禁用一个字段(效果很好)但是当用户再次点击它应该启用有问题的字段.我使用警报来确保 else 块被触发,所以我知道不是这样.

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 used alerts to make sure the else block is being fired, so I know that's not it.

代码:

$('#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');
  }
});

谢谢.

推荐答案

都好用这个:

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

这篇关于jQuery删除属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆