如何使一个复选框只读?不禁用? [英] How can I make a checkbox readonly? not disabled?

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

问题描述

我有一个表单,我必须将表单值发布到我的操作类。在这种形式我有一个复选框,需要readonly。我尝试设置 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.

那么请咨询?

推荐答案

<input type="checkbox" checked onclick="return false;" onkeydown="return false;"/>

http:// jsfiddle.net/2srjc/

如果您担心Tab顺序,只有当未按下Tab键时,才会为键按下事件返回false:

If you are worried about tab order, only return false for the keydown event when the tab key was not pressed:

<input type="checkbox" checked onclick="return false;" onkeydown="e = e || window.event; if(e.keyCode !== 9) return false;"/>

http: //jsfiddle.net/2srjc/149/

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

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