How do I disable TextBox using JavaScript?

前端 未结 4 963
时光说笑
时光说笑 2021-02-01 23:15

earlier I asked for help disabling a Button when a drop down menu item was selected. I was given some code that did the trick but now I need the same with a Textbox and for some

相关标签:
4条回答
  • 2021-02-01 23:50

    Form elements can be accessed via the form's DOM element by name, not by "id" value. Give your form elements names if you want to access them like that, or else access them directly by "id" value:

    document.getElementById("color").disabled = true;
    

    edit — oh also, as pointed out by others, it's just "text", not "TextBox", for the "type" attribute.

    You might want to invest a little time in reading some front-end development tutorials.

    0 讨论(0)
  • 2021-02-01 23:55

    With the help of jquery it can be done as follows.

    $("#color").prop('disabled', true);
    
    0 讨论(0)
  • 2021-02-02 00:01

    You can use disabled attribute to disable the textbox.

    document.getElementById('color').disabled = true;
    
    0 讨论(0)
  • 2021-02-02 00:15

    Here was my solution:

    Markup:

    <div id="name" disabled="disabled">
    

    Javascript:

    document.getElementById("name").disabled = true;
    

    This the best solution for my applications - hope this helps!

    0 讨论(0)
提交回复
热议问题