JavaScript設定input文字框只讀
有時候需要根據具體情況將文字框設定為只讀狀態,下面就是一段這樣的程式碼例項能夠實現此功能。
程式碼如下:
[HTML] 純文字檢視 複製程式碼<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> </head> <script type="text/javascript"> function isreadonly(){ var obj=document.getElementById("username"); obj.setAttribute("readOnly",true); obj.style.backgroundColor="#d2d2d2"; } window.onload=function(){ var readonly=document.getElementById("readonly"); readonly.onclick=isreadonly; } </script> <body> <form name="addform" method="post" action=""> <input type="text" id="username" name="username"> <input type="button" name="只讀" id="readonly" value="設定為只讀"/> </form> </body> </html>
點選按鈕可以將文字框設定為只讀狀態,具體可以參閱相關閱讀。
相關閱讀:
(1).setAttribute方法參閱setAttribute()函式的用法詳解一章節。
相關文章
- JavaScript 動態設定input文字框只讀JavaScript
- 設定input文字框只讀效果
- javascript動態設定input文字框的值JavaScript
- CSS 設定input文字框樣式CSS
- css設定input文字框樣式CSS
- 為input文字框設定背景圖片
- JavaScript獲取input text文字框JavaScript
- javascript input文字框新增提示文字效果JavaScript
- 單獨設定input text文字框樣式
- 設定input type為text的文字框樣式
- javascript:讓表單文字框只讀,不可編輯的方法JavaScript
- HTML中設定input等文字框為不可操作HTML
- 將textarea文字框設定為只讀和不可用簡單介紹
- javascript當文字框獲得焦點設定邊框JavaScript
- js動態設定input文字框的readonly屬性JS
- 純css設定input文字框獲取焦點時的樣式CSS
- CSS input文字框樣式CSS
- CSS input 文字框樣式CSS
- input 文字框內容居中
- CSS匹配input text文字框CSS
- input只能輸入文字框
- css設定具有指定type屬性值的input文字框的樣式CSS
- 如何使用CSS設定文字框的邊框CSS
- input文字框寬度自適應
- input文字框焦點背景變色
- comboBox設定為只讀(只選)
- javascript文字框獲取焦點設定其樣式程式碼JavaScript
- JavaScript文字框事件JavaScript事件
- JavaScript 文字框事件JavaScript事件
- javascript規定文字框不能夠輸入空格JavaScript
- easyui datebox 設定只讀UI
- input文字框的實際寬度包括邊框的
- input框type=file設定cursor:pointer的問題
- 讓input文字框文字垂直居中程式碼例項
- JavaScript設定table表格邊框JavaScript
- CSS 設定文字框游標顏色CSS
- Java 設定Word文字框中的文字旋轉方向Java
- 實現文字標題和input文字框垂直居中對齊