如何将复选框设为只读?没被禁用? [英] How can I make a checkbox readonly? not disabled?

查看:14
本文介绍了如何将复选框设为只读?没被禁用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,我必须将表单值发布到我的操作类.在这个表单中,我有一个需要只读的复选框.我尝试设置 disabled="true" 但这在发布到操作类时不起作用.

I have a form where I have to post form values to my action class. In this form I have a checkbox that needs to be readonly. I tried setting disabled="true" but that doesn't work when posting to the action class.

所以请给点建议??

推荐答案

您可以通过 css 轻松完成此操作.HTML:

You can easily do this by css. HTML :

<form id="aform" name="aform" method="POST">
    <input name="chkBox_1" type="checkbox" checked value="1" readonly />
    <br/>
    <input name="chkBox_2" type="checkbox" value="1" readonly />
    <br/>
    <input id="submitBttn" type="button" value="Submit">
</form>

CSS:

input[type="checkbox"][readonly] {
  pointer-events: none;
}

演示

这篇关于如何将复选框设为只读?没被禁用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆