.attr(“disabled”, “disabled”) issue

后端 未结 7 1380
再見小時候
再見小時候 2020-12-28 17:05

I have this function toggles the disabled attribute form a input field:

$(\'.someElement\').click(function(){     
  if (someCondition) {
     console.log($         


        
相关标签:
7条回答
  • 2020-12-28 17:25

    Try

    $(bla).click(function(){        
      if (something) {
         console.log("A:"+$target.prev("input")) // gives out the right object
         $target.toggleClass("open").prev("input").attr("disabled", "disabled");
      }else{
         console.log("A:"+$target.prev("input")) // any thing from there for a single click?
         $target.toggleClass("open").prev("input").removeAttr("disabled"); //this works
      }
    });
    
    0 讨论(0)
  • 2020-12-28 17:27

    Thank you all for your contribution! I found the problem:

    ITS A FIREBUG BUG !!!

    My code works. I have asked the PHP Dev to change the input types hidden in to input type text. The disabled feature works. But the firebug console does not update this status!

    you can test out this firebug bug by your self here http://jsbin.com/uneti3/3#. Thx to aSeptik for the example page.

    update: 2. June 2012: Firebug in FF11 still has this bug.

    0 讨论(0)
  • 2020-12-28 17:28
    $("#vp_code").textinput("enable");
    $("#vp_code").textinput("disable");
    

    you can try it

    0 讨论(0)
  • 2020-12-28 17:28

    To add disabled attribute

    $('#id').attr("disabled", "true");
    

    To remove Disabled Attribute

    $('#id').removeAttr('disabled');
    
    0 讨论(0)
  • 2020-12-28 17:31

    I was facing the similar issue while toggling the disabled state of button! After firing the removeProp('disabled') the button refused to get "disabled" again! I found an interesting solution : use prop("disabled",true) to disable the button and prop("disabled",false) to re-enable it! Now I was able to toggle the "disabled" state of my button as many times I needed! Try it out.

    0 讨论(0)
  • 2020-12-28 17:36

    Try this updated code :

    $(bla).click(function(){        
      if (something) {
         console.log($target.prev("input")) // gives out the right object
         $target.toggleClass("open").prev("input").attr("disabled", "true");
      }else{
         $target.toggleClass("open").prev("input").removeAttr("disabled"); //this works
      }
    })
    
    0 讨论(0)
提交回复
热议问题