在js方法中改变文本输入框text的字体和背景颜色

在做项目时遇到需要通过鼠标触发事件,然后在js函数中改变text文本域的颜色,下面是具体的操作,写下来帮助记忆:

function setColor (where, Color) {
    if (where == "backgroundcolour")
        document.getElementById('textarea').style.backgroundColor = Color;
    if (where == "colourtext")
        document.getElementById('textarea').style.color = Color;
}
<p>
  Card color: <input type = "text"  name = "backgroundcolour" 
                           size = "10"
                           onchange = "setColor('backgroundcolour',
                                               this.value)">
  <br>
  Text color: <input type = "text"  name = "colourtext" 
                           size = "10"
                           onchange = "setColor('colourtext',
                                               this.value)">
  <br>
</p>
<textarea id = 'textarea' name="data" cols="100" rows="10">

</textarea>
发布了9 篇原创文章 · 获赞 7 · 访问量 5496

猜你喜欢

转载自blog.csdn.net/u013455166/article/details/104062060
今日推荐