Skip to content

Instantly share code, notes, and snippets.

@PallCreaker
Last active August 29, 2015 13:56
Show Gist options
  • Save PallCreaker/9035615 to your computer and use it in GitHub Desktop.
Save PallCreaker/9035615 to your computer and use it in GitHub Desktop.
画像のクリックで_on _offを切り替える  ホバーのものっけとくよ!!!
//click
<a href="javascript:void(0)">
<img src="./../img/button/radio_off.png" alt="off" class="imgChange" /><input type="hidden" value=""/>
</a>
<script type="text/javascript">
$(function(){
$(".imgChange").click(function(){
var imgSrc = $(this).attr("src");
if($(this).attr("class") == "imgChange_on"){
$(this).attr("class", "imgChange_off")
imgSrc = $(this).attr('src').replace('_on', '_off');
$(this).attr("src", imgSrc);
$('input#radio').val('off');
}else{
$(this).attr("class", "imgChange_on")
imgSrc = $(this).attr('src').replace('_off', '_on');
$(this).attr("src", imgSrc);
$('input#radio').val('on');
}
});
});
</script>
//hover
<a href="#">
<img src="images/sample_off.jpg" alt="sample" border="0" />
</a>
<script type="text/javascript">
$(function(){
$('a img').hover(function(){
$(this).attr('src', $(this).attr('src').replace('_off', '_on'));
}, function(){
if (!$(this).hasClass('currentPage')) {
$(this).attr('src', $(this).attr('src').replace('_on', '_off'));
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment