고수님들 도와주세요 ㅠㅠ

링크를 클릭시 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,324
14년 전 조회 2,333
14년 전 조회 1,928
14년 전 조회 1,873
14년 전 조회 1,391
14년 전 조회 997
14년 전 조회 1,034
14년 전 조회 1,608
14년 전 조회 787
14년 전 조회 986
14년 전 조회 1,166
14년 전 조회 1,682
14년 전 조회 875
14년 전 조회 1,163
14년 전 조회 955
14년 전 조회 1,259
14년 전 조회 1,374
14년 전 조회 811
14년 전 조회 1,012
14년 전 조회 1,299
14년 전 조회 1,375
14년 전 조회 765
14년 전 조회 909
14년 전 조회 1,625
14년 전 조회 2,708
🐛 버그신고