向文本框插入背景图像

  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript">
  5. function bgChange(bg)
  6. {
  7. document.getElementById('x').style.background="url(" + bg + ")"
  8. }
  9. </script>
  10. </head>
  11.  
  12. <body>
  13. <p>本例演示如何向 textarea 插入背景图像。</p>
  14. <p>请把鼠标移动到图像上,textarea 会获得一幅背景图像:</p>
  15.  
  16. <table width="300" height="100">
  17. <tr>
  18. <td onmouseover="bgChange('/i/eg_bg_03.gif')"
  19. background="/i/eg_bg_03.gif"></td>
  20. <td onmouseover="bgChange('/i/eg_bg_04.gif')"
  21. background="/i/eg_bg_04.gif"></td>
  22. </tr>
  23. </table>
  24.  
  25. <form>
  26. <textarea id="x" rows="5" cols="20">
  27. This example can not be edited
  28. because our editor uses a textarea
  29. for input,
  30. and your browser does not allow
  31. a textarea inside a textarea.