如何更改textarea的背景图像

时间:2010-07-15 14:14:49

标签: javascript html coding-style

当我从textarea菜单中选择一个值时,如何更改select背景图片?

<html>
<head>
<title>  Your Title  </title>

<script>
function kool()
{
`enter code here`abc.style.background="img1.bmp"
}
</script>
</head>
<body>

<textarea name="abc">
1) Make paper airplanes out of the exam. Aim them at the instructor's left nostril. 
2) Bring cheerleaders during an exam.
</textarea>

<select id="xyz" onchange="kool()">
<option value="A">Image 1</option>
<option value="B">Image 2</option>
</select>

</body>
</html>

2 个答案:

答案 0 :(得分:2)

这应该有效:

<textarea id="text">
Lorem ipsum dolor sit amet, ...
</textarea>

<select onchange="document.getElementById('text').style.backgroundImage = 'url(' + this.value + ')';">
<option value="image1.png">Image 1</option>
<option value="image2.png">Image 2</option>
</select>

答案 1 :(得分:0)

应该是:

<script>
function kool(input)
{
   var el = document.getElementById('abc');
   el.style.backgroundImage = 'url(' + input + ')';
}
</script>
</head>
<body>

<textarea name="abc" id="abc">
1) Make paper airplanes out of the exam. Aim them at the instructor's left nostril. 
2) Bring cheerleaders during an exam.
</textarea>

<select id="xyz" onchange="kool(this.value)">
<option value="A.jpg">Image 1</option>
<option value="B.jpg">Image 2</option>
</select>

确保路径正确。