页面文本框的只读属性readonly的设置与使用focus-blur事件方法的区别

1 <html>
2     <head>
3         <title>readonly与focus-blur的区别</title>
4     </head>
5     <body>
6         <input type="text" value="test strings" id="myInput" readOnly="readonly" />
7         
8     </body>
9 </html>

首先,注意readonly的写法,当写在标签属性行时,readonly需要小写才有效。

<html>
     <head>
         <title>readonly与focus-blur的区别</title>
     </head>
     <body>
         <input type="text" value="test strings" id="myInput"  />
<script>
document.getElementById("myInput").readOnly="readonly";        
</script>
     </body>
 </html>

当在js中设置readonly的值得时候,此时的属性名为readOnly,O字母需要大写才有效

<html>
<head>
<title>无标题文档</title>
</head>

<body>
<input value="test strings" type="text" id="myInput" />
<script type="text/javascript">
document.getElementById("myInput").onfocus=function()
{
    this.blur();
}
</script>
</body>
</html>

当使用focus-blur方法模拟readonly时候,用户是无法选中文本框中的数据的,也就是无法进行拷贝操作。

总而言之,当我们使用readonly的时候一定要注意什么时候字母O需要大写什么时候需要小写。而设置readonly的属性值与使用事件方法focus-blur的差别在于,是否允许拷贝。

转载于:https://www.cnblogs.com/Arvin-wjw/p/3467114.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值