如何根据是否正在输入文本区域来更改文本区域的属性
How do I change the properties of a textarea depending on whether it is being typed into
所以我有一个网站,并且有一个文本区域。背景是白色的,文字是黑色的。如何让背景色和打字时的颜色发生变化?
只需使用 :focus 伪代码
textarea:focus {
background: red;
color: white;
}
<textarea></textarea>
<textarea rows="4" cols="50" id= "textId">
My text
</textarea>
<div id="colorChange">My DIV</div>
<script type="text/javascript">
var textAr = document.getElementById("textId");
var colorDiv = document.getElementById("colorChange");
function changeColor(){
colorDiv.style.color = "blue";
}
textAr.addEventListener('keyup',changeColor);
</script>
所以我有一个网站,并且有一个文本区域。背景是白色的,文字是黑色的。如何让背景色和打字时的颜色发生变化?
只需使用 :focus 伪代码
textarea:focus {
background: red;
color: white;
}
<textarea></textarea>
<textarea rows="4" cols="50" id= "textId">
My text
</textarea>
<div id="colorChange">My DIV</div>
<script type="text/javascript">
var textAr = document.getElementById("textId");
var colorDiv = document.getElementById("colorChange");
function changeColor(){
colorDiv.style.color = "blue";
}
textAr.addEventListener('keyup',changeColor);
</script>