改变文本框的背景颜色

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function newColor(color)
  5. {
  6. document.getElementById('x').style.background=color
  7. }
  8. </script>
  9. </head>
  10. <body>
  11.  
  12. <p>本例演示如何改变 textarea 的背景颜色。</p>
  13. <p>请把鼠标移动到下面的三个表格单元上,背景颜色将会改变:</p>
  14.  
  15. <table width="100%"><tr>
  16. <td bgcolor="red" onmouseover="newColor('red')"> </td>
  17. <td bgcolor="blue" onmouseover="newColor('blue')"> </td>
  18. <td bgcolor="green" onmouseover="newColor('green')"> </td>
  19. </tr></table>
  20.  
  21. <form>
  22. <textarea id="x" rows="5" cols="20">
  23. This example can not be edited
  24. because our editor uses a textarea
  25. for input,
  26. and your browser does not allow
  27. a textarea inside a textarea.