2013-03-06 62 views
1

我有一個HTML表單,帶有一些輸入複選框。我需要預先選擇其中的兩個,而且不可編輯。我已將「已檢查」&「禁用」在一起,但禁用的輸入未包含在表單提交中。還有其他的方式嗎?我希望複選框被選中並且不可編輯,其值將在表單提交時提交。使html複選框被選中並且不可編輯

回答

3

如果選中並禁用了您想要的外觀,然後添加一些提交所需數據的隱藏表單域。

+1

我從字面上只是想說 – 2013-03-06 05:23:18

+0

我正在輸入相同的答案。的xD – 2013-03-06 05:23:34

-1
$(":checked").on('click',function(){ //select those element which you want to make preselect and non editable... 
$(this).attr("checked","checked"); 
}); 

你並不需要禁用它...

0

請嘗試以下方法,如果你喜歡使用腳本。你沒有提到你的問題,你是否能夠使用它。我希望這會幫助你至少一點.. :)

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8" /> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
     <script> 
      $(document).ready(function(){ 
       $('.required-checkbox').each(function(index, value){ 
        $(value).change(function(){ 
         $(this).prop('checked', true); 
        }); 
       }); 
      }); 
     </script> 
    </head> 
    <body> 
     <input type="checkbox" class="required-checkbox" checked /> 
     <input type="checkbox" /> 
     <input type="checkbox" class="required-checkbox" checked /> 
     <input type="checkbox" /> 
     <input type="checkbox" /> 
     <input type="checkbox" /> 
    </body> 
</html> 
1

我有一個解決方法爲您的問題。

您可以將選中的複選框值存儲在隱藏字段中,並訪問表單提交中的隱藏字段。

在html上:

使複選框被選中和禁用。同時將隱藏字段中的選定複選框值保存爲以逗號分隔的字符串。

serevr方: 將逗號分隔字符串中的值從字符串數組中取出並將數組的值保存到數據庫中。

0

您可以在表單提交事件期間刪除這些輸入中的「禁用」狀態。

$('form').submit(function(e) { 
    var disabledInputs = $(this).find(':input:disabled'); 
    disabledInputs.removeAttr('disabled'); 
    return true; 
});