2013-10-26 59 views
0

在我的程序中我使用了圖像彈出窗口。一些圖像在主頁上滾動。圖片點擊事件

雖然我點擊圖像的意義上彈出將打開並顯示彈出窗口中的特定圖像。如何在彈出窗口中顯示圖像。現在我彈出了窗口,但是我無法在彈出窗口中顯示圖像。

這是到目前爲止我的代碼:

$("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' }); }); 
+0

您應該將img src傳遞給彈出窗口。 – vijaykumar

+1

沒有代碼沒有人可以幫你 –

+0

如果可以,請顯示一些代碼和jsfiddle。 – 2013-10-26 07:08:42

回答

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

//把這個ImageSource的你的形象窗口

編輯:

$("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' }); 
}); 

此代碼應該做的招。!

+0

,但我有10個圖像每個圖像ID是相同的。 – user2893238

+0

上面的代碼無法正常工作。 – user2893238

+2

你違背了HTML的規則。頁面應該有唯一的元素ID。 – writeToBhuwan

0
$("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)">'); 
    });