0 points

Javascript simple onclick image swap - Stack Overflow


dashboard

Sun Sep 06 2020 07:27:09 GMT+0000 (UTC)

Posted by @sailomtaaley #javascript

<script type="text/javascript">
function test()
{
    alert(window.document.pic.src);
     //alert msg print like http://localhost/test/pic1.png
    if (document.pic.src=='http://localhost/test/pic1.png'){

document.pic.src='pic2.png';
} 
else if (document.pic.src=='http://localhost/test/pic2.png'){

document.pic.src='pic1.png';
}
}
</script>
<img src="pic1.png" name="pic" onclick="test()"/>
content_copy Copy

เมื่อคลิกที่รูป จะสลับเปลี่ยนรูป

https://stackoverflow.com/questions/4363439/javascript-simple-onclick-image-swap