html学习之input不可编辑

本文详细介绍了HTML中如何使用disabled和readOnly属性来禁用输入框的编辑功能,并提供了具体的示例代码。无论属性值为何种形式,只要包含这两个属性之一即可实现禁用效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(1)不可编辑属性    disabled:和readonly

     disabled="true/disable" 此果文字会变成灰色,不可编辑。 
     readOnly="true" 文字不会变色,也是不可编辑的

        注意:其实属性值true,true/disable是不起作用的,只要含有属性 字段readOnly 或者disabled就可以设置为不可编辑,

例如:disabled="任意字符" readOnly="任意字符"都是可以的,readonly="false"也是不可编辑

举例:

<input type="text" name="lname" disabled="disabled" />
<input type="text" name="lname" readOnly="true" />
<input type="text" name="lname" readOnly="false" />
<input type="text" name="lname" disabled />
<input type="text" name="lname" readOnly />
也可以运用事件
<input type="text" name="input" value="失焦事件使其无法编辑" οnfοcus="this.blur()">


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值