2013-03-06 28 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; 
});