Friday 4 October 2013

How to change the image on mouseover

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript">
        cc = 0;
        function changeimage() {
            if (cc == 0) {
                cc = 1;
                document.getElementById('myimage').src = "Koala.jpg";
            }
            else {
                cc = 0;
                document.getElementById('myimage').src = "Tulips.jpg";
            }
        }

        function chaimage() {
            if (cc == 0) {
                cc = 1;
                document.getElementById('Img1').src = "Koala.jpg";
            }
            else {
                cc = 0;
                document.getElementById('Img1').src = "Tulips.jpg";
            }
        }
</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
     
 
<h1 onmouseover="style.color='red'"
onmouseout="style.color='black'">
When Mouse over this text color will be Red And when will be out Text color will be Black</h1><br />
Above text color will change on mouseover and mouseout<hr />
 <br />


 
 <img id="myimage"  onmouseout="changeimage()" onmouseover="changeimage()"
border="0" src="Tulips.jpg"
width="300" height="100" />
<p>Above Image will change when we mouseover on image and change the image when we mouse out  from image</p><hr />
 

 <br />

<img id="Img1"  onclick="chaimage()"
border="0" src="Tulips.jpg"
width="300" height="100" />
<p>Above Image will change when we click on image and change the image when we change on image</p>
    </div>
    </form>
</body>
</html>


Default.aspx.cs

There is no need of to write the code in Default.aspx.cs page

The Output is 


No comments:

Post a Comment