한번 클릭 했을때 아래 처럼 off 가 on 이 되는데
$("#chk").click(function() {
$(".imgover").attr("src", $(".imgover").attr("src").replace("off","on"));
});
한번더 클릭 하면 off 에서 on 으로 바꾸고 싶은데 잘 안되네요..
|
답변 2개 / 댓글 1개
채택된 답변
+20 포인트
src 를 토글 하려나 보네요
var src_on = false;
$("#chk").click(function() {
if(src_on){
$(".imgover").attr("src", $(".imgover").attr("src").replace("on","off"));
src_on = false;
}else{
$(".imgover").attr("src", $(".imgover").attr("src").replace("off","on"));
src_on = true;
}
});
답변에 대한 댓글 1개
2017-08-29 (화) 17:56:17
Copy
$("#chk").click(function() {if($(".imgover").attr("off")){ $(".imgover").attr("src", $(".imgover").attr("src").replace("off","on")); }else{ $(".imgover").attr("src", $(".imgover").attr("src").replace("on","off")); } });
html코드가 안보이니 뭔지 모르겟네요
대충 위와같은 식으로 하면 될듯합니다.
이런식으로 ??
답변을 작성하려면 로그인이 필요합니다.