即使在删除readonly后也无法使TextArea可编辑:Html

时间:2018-01-23 01:55:29

标签: javascript jquery html

JavaScript的:

|}

HTML:

var editBtn = document.getElementById('editBtn');
var saveBtn = document.getElementById('saveBtn');
var textAreaHtml = document.getElementsByTagName("textarea");

editBtn.addEventListener('click', function (e) {
    textAreaHtml[0].removeAttribute('readonly');
    textAreaHtml[0].readOnly = 'false';
});

saveBtn.addEventListener('click', function (e) {
    textAreaHtml[0].removeAttribute('readonly');
    textAreaHtml[0].readOnly = 'true';
});

我有两个按钮,保存和编辑。我已经为编辑保存了事件监听器并保存以使文本区域可编辑,但这不起作用。我无法在UI中编辑TextArea?有什么我想念的吗?

2 个答案:

答案 0 :(得分:1)

稍微调整点击事件处理程序,您就应该开展业务。

cout

您的编辑按钮将readOnly设置为false,但readonly是一个布尔属性。当它存在时,它会使textarea只读,无论它是否具有真值或假值。

答案 1 :(得分:0)

使用HTML属性readonly

而不是contenteditable

我从未使用过readonly但是通过切换contenteditable上的布尔值你应该做饭!

https://www.w3schools.com/tags/att_contenteditable.asp

相关问题