admin管理员组文章数量:1327849
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!
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!
Share Improve this question edited Feb 17, 2017 at 0:08 Moses Davidowitz 98212 silver badges29 bronze badges asked Feb 16, 2017 at 22:11 Rohan VasishthRohan Vasishth 2411 gold badge6 silver badges14 bronze badges 2- 1 Do you have code that you tried that didn't work? Could you please post that? – zgood Commented Feb 16, 2017 at 22:13
- For more info, see alert() and .addEventHandler() – RobM Commented Feb 16, 2017 at 22:21
3 Answers
Reset to default 2Just 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./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img id="img" src="images/photostack.png" alt="" />
Lots of ways to do this... Here is a short one inline with your html:
<img src="images/photostack.png" alt="" onclick="alert('you clicked it')" />
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
本文标签: javascriptPopup alert on image clickStack Overflow
版权声明:本文标题:javascript - Pop-up alert on image click. - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742212893a2434040.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论