【问题标题】:How do I change the properties of a textarea depending on whether it is being typed into如何根据是否输入文本来更改文本区域的属性
【发布时间】:2019-03-30 00:19:52
【问题描述】:

所以我有一个网站,我有一个文本区域。背景为白色,文字为黑色。输入时如何使背景颜色和颜色发生变化?

【问题讨论】:

  • 请分享您已经完成的代码sn-p。

标签: html css textarea


【解决方案1】:

只需使用 :focus 伪代码

textarea:focus {
  background: red;
  color: white;
}
<textarea></textarea>

【讨论】:

【解决方案2】:
<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多