how to save data by disabled text box?

2019-08-22 00:04发布

问题:

In my jsp page, 1 checkbox, 2 textbox and 1 submit button. The checkbox is used for enabling and disabling the text box. Data saved when textbox is enable but not saved when textbox is disable.

following code is for toggle.

function toggleFields(status){
    if (status==false){
        $("#textbox1").removeAttr("disabled");
        $("#textbox2").removeAttr("disabled");
        } 
        else {
        $("#textbox1").attr("disabled", "disabled");
        $("#textbox2").attr("disabled", "disabled");
    }       
}

please help me in this.

回答1:

You can use readonly instead of disabled.

 $("#textbox1").attr("readonly", true);

Your code would be

function toggleFields(status){
    if (status==false){
        $("#textbox1").attr("readonly", false);
        $("#textbox2").attr("readonly", false);
        } 
        else {
        $("#textbox1").attr("readonly", true);
        $("#textbox2").attr("readonly", true);
    }       
}