Ⅰ 如何用javascript代碼控制input標簽的readonly或disabled屬性
我喜歡用JQuery的attr()方法,超方便,也強大。
比如:(前提是先引入JQuery)
<input type="button" class="button" />
$(".button").attr("disabled","disabled");
當然,你也可以使用原生js來寫,跟樓上的差不多,其實都一樣,看你喜歡吧。不過我不喜歡用ID來限制DOM元素,因為有很多時候如果你不清楚CSS的優先順序的話,會出現很多麻煩,用ID來限制元素優先順序很高的,不過那是另外別的問題了跟你這沒關系
Ⅱ js去除 html 中 input 的readOnly屬性
<inputtype="text"readonlyid=aa>
<inputtype=buttononclick="document.all.aa.readOnly=false"value="input">

拓展資料:
readonly 屬性規定輸入欄位為只讀。只讀欄位是不能修改的。不過,用戶仍然可以使用 tab 鍵切換到該欄位,還可以選中或拷貝其文本。readonly 屬性可以防止用戶對值進行修改,直到滿足某些條件為止(比如選中了一個復選框)。然後,需要使用 JavaScript 消除 readonly 值,將輸入欄位切換到可編輯狀態。readonly 屬性可與 <input type="text"> 或 <input type="password"> 配合使用。
Ⅲ 關於JS如何實現表單的readonly
當讓可以
function check(){
var txtN = document.getElementById("test");
txtN.setAttribute("readonly",true,0);
}
setAttribute 這個方法一定要注意,有三個參數
object.setAttribute(sName, vValue [, iFlags])
last arg
iFlags: Optional. Integer that specifies one the following flags: 0 When the attribute is set, it overwrites any attributes with the same name, regardless of their case.
1 Default. The case of the attribute that you set is respected when it is set on the object.
Ⅳ js控制readonly只讀為什麼onblur還會執行,怎麼讓他不執行
寫一句
obj.onblur=function(){return false;};
這樣onblur後什麼都不執行就可以了
Ⅳ js readonly 怎麼控制輸入框內的可讀不可讀,想讓一個不可讀輸入框中的內容在點擊相應按鈕的情況下改為可
這樣:
<script>function doclick1(){
var txtN = document.getElementById("contactus5");
txtN.readOnly = false;
}
</script>
<input type="text" id="contactus5" readonly>
<input type="button" name="button4" value="修改" onclick="doclick1();" />
Ⅵ 關於javascript中readonly的問題
readonly是這標簽個的一個屬性說明這個文本框只能讀不能編輯,"/>"是html中的標簽結束標志
Ⅶ 如何用Javascript代碼控制input標簽的readonly或disabled屬性
<input type="text" id="Cs" value="123" />
<script type="text/javascript">
var Js_Cs= document.getElementById("Cs");
Js_Cs.readOnly=true;
</script>
PS:此時JavaScript代碼要寫到<input>;