고수님들 도와주세요 ㅠㅠ

링크를 클릭시 id=A라는 TD에 배경값을 B로 바꾸려합니다..

구현은 어찌저찌해서 짜집기해서 해봤는데 작동이 안됩니다...

<a href="javascript:(A.style.backgroundImage = "url(B)")">

전혀 바뀌질 않습니다..

고수님들 도와주세요 ㅠㅠ


|

댓글 3개

<script>
function changeImage(id, url) {
var target = document.getElementById(id);
target.style.backgroundImage = "url(" + url +")";
}
</script>

<table>
<tr><td id="test1">#test1</td></tr>
<tr><td id="test2">#test2</td></tr>
</table>

<a href="javascript:changeImage('test1', 'http://www.google.co.kr/logos/2012/newyearsday-2012-res.jpg')">변경 test1</a>
<span style="cursor:pointer" onclick="changeImage('test2', 'http://www.google.co.kr/logos/2012/newyearsday-2012-res.jpg')">변경 test2</span>

----
anchor 태그보다는 span 같은 것 쓰시고 pseudo javascript보다는 event를 쓰시는 것이 좋습니다용.
감사합니다!! ㅠㅠ
jquery 를 쓰시면
jQuery(document).ready(function(){
jQuery("#A").click(function(){
jQuery(this).css("background-image","url(B)");
});
});
댓글을 작성하시려면 로그인이 필요합니다.

팁게시판

디자인과 관련된 유용한 정보를 공유하세요. 질문은 상단의 QA에서 해주시기 바랍니다.

+
제목 글쓴이 날짜 조회
14년 전 조회 3,347
14년 전 조회 2,361
14년 전 조회 1,961
14년 전 조회 1,897
14년 전 조회 1,417
14년 전 조회 1,026
14년 전 조회 1,063
14년 전 조회 1,636
14년 전 조회 811
14년 전 조회 1,006
14년 전 조회 1,188
14년 전 조회 1,701
14년 전 조회 898
14년 전 조회 1,182
14년 전 조회 972
14년 전 조회 1,278
14년 전 조회 1,391
14년 전 조회 829
14년 전 조회 1,036
14년 전 조회 1,318
14년 전 조회 1,393
14년 전 조회 784
14년 전 조회 926
14년 전 조회 1,642
14년 전 조회 2,726