当我从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>
答案 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>
确保路径正确。