jQuery 图片点击事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19603909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:16:22  来源:igfitidea点击:

Image Click Event

jquery

提问by Prem Anandh

In my program I used image pop up window. some what images scrolling in home page.

在我的程序中,我使用了图像弹出窗口。一些什么图像在主页滚动。

While I click on the image in the sense the pop up will open and show the particular image in popup windows. How I can show the image in pop up window. Now I got the pop up window but I can't show the image in the popup window.

当我在某种意义上单击图像时,弹出窗口将打开并在弹出窗口中显示特定图像。如何在弹出窗口中显示图像。现在我得到了弹出窗口,但我无法在弹出窗口中显示图像。

Here is my code so far:

到目前为止,这是我的代码:

$("img").click(function(){
     var $dialog = $('<div></div>') 
         .html(' <img src="localhost:81/keprandemo/media/catalog/product/cache/1/…; width="200" height="200" alt="Milk(1 lit)">') 
         .dialog({ autoOpen: true, resizable: false, draggable: false, width: 600, height:600, modal: true, title: 'Create Your Own PopUp Window' }); }); 

回答by writeToBhuwan

var ImageSource="";
$('.yourImageClass').click(function(){
     ImageSource=$(this).attr('src');
});

//Pass this ImageSource to your image window

//将此 ImageSource 传递到您的图像窗口

EDIT:

编辑:

$("img").click(function(){
    var source=$(this).attr('src');
    var $dialog = $('<div></div>') 
         .html('<img src="'+source+'" width="200" height="200" alt="Milk(1 lit)">') 
         .dialog({ autoOpen: true, resizable: false, draggable: false, width: 600, height:600, modal: true, title: 'Create Your Own PopUp Window' }); 
}); 

This code should do the trick.!

这段代码应该可以解决问题。!

回答by Amol Navsupe

 $("img").click(function(){
 var $dialog = $('<div id="urID"></div>') 
     .dialog({ autoOpen: true, resizable: false, draggable: false, width: 600, height:600, modal: true, title: 'Create Your Own PopUp Window' });
   //ur div id name.
   $('#urID').html('<img src="localhost:81/keprandemo/media/catalog/product/cache/1/…; width="200" height="200" alt="Milk(1 lit)">');
  });