2016-09-23 37 views
0

我有一個HTML輸入頁面,可以通過選中名爲undefined的複選框來禁用輸入字段。返回到HTML頁面時禁用輸入字段

當我檢查未定義並轉到下一頁並返回到輸入頁面時,必須選中複選框並禁用輸入字段。

現在,當我回來的輸入頁面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

我在這裏很難理解你的問題。首先,這是一個錯字嗎?也許你在某處使用這個值:document.getElementById(value).value ='und ** i ** fined';應該是document.getElementById(value).value ='undefined';' – Ted

+0

On pageload or DOM已經應該觸發一些JavaScript來評估複選框的狀態並相應地更新輸入。因爲(某些?)瀏覽器持續存在表單值,所以如果向後導航。 –

回答

0
$(document).ready(function(){ 

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

});