让input变成不可编辑状态的方法
生活随笔
收集整理的這篇文章主要介紹了
让input变成不可编辑状态的方法
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
有時候,我們希望表單中的文本框是只讀的,讓用戶不能修改其中的信息,如使<input type="text" name="input1" value="中國"> 的內容,"中國"兩個字不可以修改。實現(xiàn)的方式歸納一下,有如下幾種。方法1: onfocus=this.blur() 當鼠標放不上就離開焦點
<input type="text" name="input1" value="中國" οnfοcus=this.blur()>方法2:readonly
<input type="text" name="input1" value="中國" readonly>
<input type="text" name="input1" value="中國" readonly="true">方法3: disabled
<input type="text" name="input1" value="中國" disabled="true">完整的例子:<input name="ly_qq" type="text" tabindex="2" onMouseOver="this.className='input_1'" onMouseOut="this.className='input_2'" value="123456789" disabled="true" readOnly="true" />
disabled="true" 此果文字會變成灰色,不可編輯。
readOnly="true" 文字不會變色,也是不可編輯的css屏蔽輸入:<input style="ime-mode: disabled">有兩種方法第一:disabled="disabled"這樣定義之后被禁用的 input 元素既不可用,也不可點擊。第二:readonly="readonly" 只讀字段是不能修改的。不過,用戶仍然可以使用 tab 鍵切換到該字段,還可以選中或拷貝其文本;
?
轉載于:https://www.cnblogs.com/sxz2008/p/6418806.html
總結
以上是生活随笔為你收集整理的让input变成不可编辑状态的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jenkins之qq企业邮箱配置
- 下一篇: 建设银行客服电话多少?怎么转人工服务?