Javascript 如何更改文本区域的背景图像
从Javascript 如何更改文本区域的背景图像,javascript,html,coding-style,Javascript,Html,Coding Style,从选择菜单中选择值时,如何更改文本区域背景图像 <html> <head> <title> Your Title </title> <script> function kool() { `enter code here`abc.style.background="img1.bmp" } </script> </head> <body> <textarea name="abc"> 1
选择
菜单中选择值时,如何更改文本区域
背景图像
<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>
你的头衔
函数库()
{
`在此处输入代码`abc.style.background=“img1.bmp”
}
1) 用纸飞机代替考试。将它们对准讲师的左鼻孔。
2) 考试时带拉拉队。
图1
图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
图2
它应该是:
<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>
函数库(输入)
{
var el=document.getElementById('abc');
el.style.backgroundImage='url('+input+');
}
1) 用纸飞机代替考试。将它们对准讲师的左鼻孔。
2) 考试时带拉拉队。
图1
图2
确保路径正确。在这里,我在哪里指定图像的路径??在
的值=“
中!在您的代码中,我如何跟踪我的textarea,我的意思是我的textarea实际上也在iframe中,我给了+1,如何设置我的textarea路径您的textarea在iframe中?尝试以下操作:window.frames['dork'].getElementById('id').style.etc
,将id
替换为iframe
url()中textarea
属性的实际id
,这样做不起作用;)(为雅编辑)@Douwe M:谢谢,伙计,我忘了那些话:)