How to change font-color for disabled input?

后端 未结 10 1106
逝去的感伤
逝去的感伤 2020-12-02 12:48

I need to change the style for a disabled input element in CSS.



        
10条回答
  •  误落风尘
    2020-12-02 13:35

    It seems nobody found a solution for this. I don't have one based on only css neither but by using this JavaScript trick I usually can handle disabled input fields.

    Remember that disabled fields always follow the style that they got before becoming disabled. So the trick would be 1- Enabling them 2-Change the class 3- Disable them again. Since this happens very fast user cannot understand what happened.

    A simple JavaScript code would be something like:

    function changeDisabledClass (id, disabledClass){
    var myInput=document.getElementById(id);
    myInput.disabled=false;             //First make sure it is not disabled
    myInput.className=disabledClass;    //change the class
    myInput.disabled=true;             //Re-disable it
    }
    

提交回复
热议问题