2010-07-15 6 views
0

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

이 작동합니다 :

<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> 
+0

내 이미지에 대한 경로는 어디에 지정합니까? style.backgroundImage = 'url ('img1.bmp + this.value + ')'; " – subanki

+0

'value ="에서'

+0

wow Douwe ur awsome, 고맙네, 너의 코드에서 – subanki

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> 

이 경로가 올바른지 확인하십시오.

+0

'url()'은 JavaScript 기능이 아니기 때문에 작동;) (나중에 편집 됨) –

+0

@Douwe M .: Thanks buddy, 나는 그 따옴표를 잊었다 :) – Sarfraz

관련 문제