简体   繁体   中英

Add click event of img src tag in html

I am new in HTML,

I have 2 HTML pages page1 and Page2

Page1:

<html>
<head>
<title>IOS_landing_V02</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (IOS_landing_V02.psd) -->
<table id="Table_01" width="1024" height="768" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <img src="IOS_landing_V02_01.jpg" width="1024" height="20" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="IOS_landing_V02_02.jpg" width="1024" height="112" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="IOS_landing_V02_03.jpg" width="1024" height="422" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="IOS_landing_V02_04.jpg" width="1024" height="1" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="IOS_landing_V02_05.jpg" width="1024" height="213" alt=""></td>
    </tr>
</table>
<!-- End Save for Web Slices -->
</body>
</html>

On click of last img (src="IOS_landing_V02_05.jpg") i want to load another HTMl page ie Page2

How to do this ?

使用会重定向您a锚标记包裹您的img标记。

<a href="page2.html"><img src="IOS_landing_V02_05.jpg" width="1024" height="213" alt=""></a>

you can do it this way: Wrap your image with <a> tag, then add a link to your second page using the href attribute.

<td>
        <a href="page2.html">  
            <img src="IOS_landing_V02_05.jpg" width="1024" height="213" alt="">  
       </a>  
</td>

Wrap the last img inside a link like this :

<a href="pathToPage2.html">
  <img src="IOS_landing_V02_05.jpg" width="1024" height="213" alt="">
</a>

Now clicking on it, will load page2 .

First set on click event for your image like this:

<img src="IOS_landing_V02_05.jpg" width="1024" height="213" alt="" onclick='newhtml()'>

// Function in head part
<script>
function Previewmode()
{
// load new html page
   window.open("http://newpage.html");   
}   
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM