html - 更改文本区域占位符 onclick 的颜色
问题描述
假设我有一个按钮和一个文本区域。textarea占位符的正常状态是灰色的。单击按钮时,它应该将占位符更改为黑色。我该怎么做?
解决方案
::placeholder
是将控制输入的占位符文本的伪类...您可以在类中设置它,然后切换类或在单击时将类添加到元素中。
let ta = document.getElementById('ta')
function changeTAText(){
// the following would toggle on each click
//=> ta.classList.toggle('placeHolderText')
// The following would add it without the
// ability to toggle on click
ta.classList = 'placeHolderText';
}
btn.addEventListener("click", changeTAText)
.placeHolderText::placeholder {
color: black;
}
<textarea id="ta" placeholder="enter your text here"></textarea>
<button id="btn">Change Color of Placeholder Text</button>
推荐阅读
- python - 在python中访问组的一行
- node.js - 使用 node.js 将图像从颤振上传到服务器
- email - 如何在 gmail 消息中添加电子邮件标记?| Gmail 收件箱操作
- java - 如何将访问令牌保存在 apache camel 的代码级别内,这样如果它存在就不需要调用 auth api?
- python - 计算自日期列以来的天数
- .net - 在 Graphql 我需要显示列表
- ios - ios 中的 WKWebView。如何使用属性禁用页面子元素的滚动反弹 - 溢出:(自动||滚动)
- sql - 将 oid 转换为 json 作为 int 而不是 string
- javascript - 不知道如何映射此 json 数据以显示在图表中
- python - 从python中的excel表中获取数据