고수님들 도와주세요 ㅠㅠ

링크를 클릭시 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,322
14년 전 조회 2,331
14년 전 조회 1,926
14년 전 조회 1,870
14년 전 조회 1,389
14년 전 조회 995
14년 전 조회 1,032
14년 전 조회 1,605
14년 전 조회 784
14년 전 조회 983
14년 전 조회 1,162
14년 전 조회 1,681
14년 전 조회 872
14년 전 조회 1,162
14년 전 조회 953
14년 전 조회 1,258
14년 전 조회 1,373
14년 전 조회 809
14년 전 조회 1,011
14년 전 조회 1,297
14년 전 조회 1,372
14년 전 조회 763
14년 전 조회 907
14년 전 조회 1,622
14년 전 조회 2,706
🐛 버그신고