고수님들 도와주세요 ㅠㅠ

링크를 클릭시 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,337
14년 전 조회 2,342
14년 전 조회 1,941
14년 전 조회 1,884
14년 전 조회 1,399
14년 전 조회 1,009
14년 전 조회 1,046
14년 전 조회 1,619
14년 전 조회 797
14년 전 조회 994
14년 전 조회 1,177
14년 전 조회 1,692
14년 전 조회 884
14년 전 조회 1,174
14년 전 조회 964
14년 전 조회 1,266
14년 전 조회 1,384
14년 전 조회 819
14년 전 조회 1,023
14년 전 조회 1,307
14년 전 조회 1,380
14년 전 조회 772
14년 전 조회 914
14년 전 조회 1,631
14년 전 조회 2,713