简体   繁体   中英

How to enable/disable a text box on clicking a button

For example my page has a text box which already has some value and the readonly option for it is "true" , when the edit button is clicked next to the text box , the editing option in text box is enabled. How do I implement enabling the textbox when i click on a button.

function func() {
    $("input:button[name='button1']").click(function() {
        $("#text11").val($(this).val()).attr("disabled", "disabled");
        if($(this).val() != "") { 
            $("#text11").attr("disabled", "").focus();
        } 
    });
}
<input type="text" name="text11" readonly="readonly" value="Editing is disabled">
<input type="button" value="edit" name="button1">

which is when I click this button , the readonly option in textbox should be disabled.How do I do that ?

basically you just want to add the attribute disabled to your element to stop users using it.

$('#disablebutton').click(function(){
    $('#textfieldToClose').attr('disable');
});

<input type="text" name="text11" readonly="readonly" id="textfieldToClose">
<input type="button" value="edit" name="button1" id="disablebutton">

i believe this should work, haven't tested it mind.

You need to use HTML DOM objects...

http://www.w3schools.com/jsref/default.asp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM