我创建了缩略图视图。当用户点击时,我希望真实的图片弹出在对话框中。这个功能第一次运行正常,但是一旦jQuery的'click'事件触发了一个缩略图,它就再也不会触发了,除非我重新加载整个页面。我尝试在对话框关闭时重新绑定单击事件,但没有帮助。以下是我的代码:
$(document).ready(function()
{
$("#tabs").tabs();
$(".selector").tabs( {selected: 0} );
$("img.gallery").live('click',
function()
{
var src= $(this).attr('src');
var popurl = src.replace("thumbs/", "");
PopUpImage(popurl,$(this));
});
// Preload animation for browser cache
var ajaximg = new Image();
ajaximg.src = 'images/ajax-loader.gif';
});
function LoadProgramsAccordion()
{
$(function() {
$("#programsaccordion").accordion({
autoHeight: false,
navigation: true,
collapsible: true
});
});
$(function() {
$("#programsaccordioninner").accordion({
autoHeight: false,
navigation: true,
collapsible: true
});
});
$(function() {
$("#policiesaccordioninner").accordion({
autoHeight: false,
navigation: true,
collapsible: true
});
});
$(function() {
$("#registrationaccordioninner").accordion({
autoHeight: false,
navigation: true,
collapsible: true
});
});
$('.accordion .head').click(function() {
$(this).next().toggle();
return false;
}).next().hide();
}
function LoadGalleryView()
{
$('img.gallery').each(function(){
$(this).hover(function(){
$(this).attr('style', 'height: 100%; width: 100%;');
}, function(){
$(this).removeAttr('style');
});
});
}
function CheckImage(img,html,source)
{
if ( img.complete )
{
$('#galleryProgress').html('');
var imgwidth = img.width+35;
var imgheight = img.height+65;
$('<div id="viewImage" title="View"></div>').html(html).dialog(
{
bgiframe: true,
autoOpen: true,
modal: true,
width: imgwidth,
height: imgheight,
position: 'center',
closeOnEscape: true
});
}
else
{
$('#galleryProgress').html('<img src="images/ajax-loader.gif" /><br /><br />');
setTimeout(function(){CheckImage(img,html);},50);
}
}
function PopUpImage(url,source)
{
var html = '<img src="'+url+'" />';
var img = new Image();
img.src = url;
if ( ! img.complete )
{
setTimeout(function(){CheckImage(img,html,source);},10);
}
}
PopUpImage()只有在第一次单击图像时才会执行,我无法弄清如何重新绑定。