本文介紹了使用 JavaScript 使文本框可編輯的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個帶有 readonly="readonly"
的文本框,這意味著我無法對其進行編輯.但我想要的是讓這個文本框在用戶雙擊它時可編輯.
I've a textbox with readonly="readonly"
that means I can not edit it. But what I want is to make this textbox editable when user double clicks on it.
我嘗試過的是:
<input size="10" readonly="readonly" ondblclick="setEditable(this)"/>
在 JavaScript 中:
and in JavaScript:
function setEditable(i){
i.readonly = false;
}
但這不起作用.那么當用戶雙擊文本框時,我怎樣才能使文本框可編輯,它是只讀的?
But this does not worked. So how can I make a textbox editable, which is readonly, when user double clicks on it?
推薦答案
更新:
再次使其只讀:
var el = document.getElementById('txt');
el.onblur = function(){
this.setAttribute('readonly');
};
<小時>
你可以這樣做:
You can do this:
<input size="10" readonly="readonly" id="txt" />
JS:
var el = document.getElementById('txt');
el.ondblclick = function(){
this.removeAttribute('readonly');
};
這篇關于使用 JavaScript 使文本框可編輯的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!