我已經使用「只讀」屬性的文本框,使文本框不可編輯,我可以知道如何禁用只讀屬性點擊按鈕。我們可以使用任何腳本來做到這一點嗎?禁用只讀文本框onclicking按鈕
<input type="text" name="" value="" readonly="readonly"/><br/>
<input type="submit" name="" value="update" onclick="" />
我已經使用「只讀」屬性的文本框,使文本框不可編輯,我可以知道如何禁用只讀屬性點擊按鈕。我們可以使用任何腳本來做到這一點嗎?禁用只讀文本框onclicking按鈕
<input type="text" name="" value="" readonly="readonly"/><br/>
<input type="submit" name="" value="update" onclick="" />
你可以做兩件事情:
readonly
(不區分大小寫)屬性,使用removeAttribute
readOnly
(案敏感)財產至false
HTML:
<input id="myInput" type="text" readonly="readonly" /><br />
<input id="myButton" type="submit" value="update" />
JS(選項1):[Demo]
document.getElementById('myButton').onclick = function() {
document.getElementById('myInput').removeAttribute('readonly');
};
JS(選項2):[Demo]
document.getElementById('myButton').onclick = function() {
document.getElementById('myInput').readOnly = false;
};
非常感謝! – Anand
好吧,要簡單!你可以使用jQuery去除這個屬性(jQuery會很簡單,你也可以使用JS來做到這一點)。下面是該代碼:
$('input[type=submit]').click(function() {
$('input[type=text]').removeAttr('readonly');
})
需要設置的readOnly
屬性元素到false
您可以使用document.getElementById,它通過其ID
HTML參考元素,在這裏,我添加了ID來元素
<input type="text" id="myTextBox" name="" value="" readonly="readonly"/><br/>
<input type="submit" id="myButton" name="" value="update" />
的JavaScript,在這裏你可以看到readOnly
屬性設置爲false。
document.getElementById('myButton').onclick = function() {
document.getElementById('myTextBox').readOnly =false;
};
此外,我建議你使用的不是type="submit"
的jQuery或JavaScript '類型= 「按鈕」',你有什麼用? – Satpal