Disable readonly to text box onclicking the button

后端 未结 3 500
醉话见心
醉话见心 2021-01-04 06:07

I have used "readonly" attribute to the textbox which makes the textbox non editable and may i know how to disable the readonly attribute on clicking the button. c

3条回答
  •  独厮守ぢ
    2021-01-04 06:50

    You need to set readOnly property of element to false

    You can use document.getElementById(), it reference to the element by its ID

    HTML, Here I have added id to elements


    JavaScript, Here you can see readOnly property to false.

    document.getElementById('myButton').onclick = function() {
       document.getElementById('myTextBox').readOnly =false;
    };
    

    DEMO

    Additionally, I would suggest you to use 'type="button"' instead of type="submit"

提交回复
热议问题