返回HTML页面时禁用输入字段

时间:2016-09-23 06:50:55

标签: javascript html

我有一个HTML输入页面,可以通过选中名为 undefined 的复选框来禁用输入字段。

当我检查未定义并转到下一页并返回到输入页面时,必须选中复选框并禁用输入字段。

现在当我回到输入页面时,选中了 checkbox,但input field不是disabled

下面是我的javascript功能代码和输入页面代码段。请帮帮我。

javascript function:

    function disable_input_field(value){    
    var input_field = document.getElementById("person_" + value);     
    if ($("#undefined_" + value).is(":checked")) {       
        input_field.disabled = true;         
        input_field.style.backgroundColor = "#e6e6e6";       
        document.getElementById(value).value = 'undifined';     
    }else{      
        input_field.disabled = false;       
        input_field.style.backgroundColor = "#ffffff";      
        document.getElementById(value).value = '';     
    } 
}

输入页面代码段:

<tr>                     
<td nowrap class="auto-style34" colspan="3" style="height: 40px;">data</td>                         
<td nowrap class="auto-style39" colspan="3">                            
    <input type="text" style="background-color: white;color: black;border-style:solid;height: 25;ime-mode: active;" id="person_data" name="person_data" size="50" value='<?php echo person_data ?>'>                     
    </td>                       
    <td nowrap class="auto-style39" colspan = "3">                      
    <?php if($check_data != ''){ print_r("if");?> 
    <input type="checkbox" checked name="undefined_data" id="undefined_data" onclick="disable_input_field('data')" >undefined 
    <?php }else{ print_r("else");?>                             
    <input type="checkbox" name="undefined_data" id="undefined_data" onclick="disable_input_field('data')" >undefined                       
    <?php }?>
    <input type="hidden" name="data" id="data">
    </td>

返回输入页面时,$check_data变为非空。

1 个答案:

答案 0 :(得分:0)

$(document).ready(function(){

if($("#undefined_" + value).is(":checked")){
        input_field.disabled = true;         
        input_field.style.backgroundColor = "#e6e6e6";       
        document.getElementById(value).value = 'undifined';  
}

});