如何使用 javascript 将属性添加到 <textarea>?
How to add attributes to a <textarea> using javascript?
editElement.addEventListener("click", ()=>{
textComment.setAttribute("disabled", true)
textComment.classList.add("uwu")
})
我正在尝试从 .js 向我的 <textarea>
添加一些属性,但我无法使其工作
将您的代码与函数一起使用而不是添加事件监听器是可行的。
function handleClick() {
const demoTextArea = document.querySelector('#demo');
demoTextArea.setAttribute('disabled', true);
console.log(demoTextArea);
}
<div>
<button onclick="handleClick()">disable input</button>
</div>
<textarea id="demo"> demo </textarea>
这是一个demo
editElement.addEventListener("click", ()=>{
textComment.setAttribute("disabled", true)
textComment.classList.add("uwu")
})
我正在尝试从 .js 向我的 <textarea>
添加一些属性,但我无法使其工作
将您的代码与函数一起使用而不是添加事件监听器是可行的。
function handleClick() {
const demoTextArea = document.querySelector('#demo');
demoTextArea.setAttribute('disabled', true);
console.log(demoTextArea);
}
<div>
<button onclick="handleClick()">disable input</button>
</div>
<textarea id="demo"> demo </textarea>
这是一个demo