简体   繁体   中英

Pop-up alert on image click.

I have a question on how you spawn a pop-up when an image is clicked. I want a pop up to be some sort of alert. Here is my current html code I am working with:

<div>
 <div class="Zipshare">
    <span class ="projectIcons">
      <a href="">
        <img src="images/photostack.png" alt="" />
      </a>
    </span>
    <span class="caption"><h6>Photostack</h6></span>
</div> 

I have seen other posts describing how to spawn an alert view but don't know how to link it to an image. I was thinking a doing it through some sort of href link but can't figure it out.

Any help would be appreciated!

有很多方法可以做到这一点...这是您的html的一小段内联:

<img src="images/photostack.png" alt="" onclick="alert('you clicked it')" />

Just add the onclick attribute

<img src="images/photostack.png" onclick="alert('Hello World')" alt="" />

Or use jQuery:

 $( "#img" ).click(function() { alert( "Hello World jQuery" ); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <img id="img" src="images/photostack.png" alt="" /> 

function pictureRc() {
alert("You right clicked that image!")}

This is my function I used in js and the html looked like this:

<img src="pic.jpg" oncontextmenu="pictureRc()">

So when you right click it makes an alert. I know this is late but for anyone finding this thread later thought it might help!

just change the oncontextmenu to onclick for left click

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