在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>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章