0

我有一个 index page index.php,当用户点击一个项目时(为了这个问题,假设该项目包含在一个名为 的 html 页面上aeffect.html),它加载aeffect.html到一个 div 中:

<div id="popupContainer"></div>

它包含在 oncontained on 上index.php

不过,上面有很多项目index.php,每个项目都有一个关闭按钮。我试图使用这个变量来清空popupContainer,希望它将它重置为空,然后aeffect.html消失。

//Close property
$("a.close").click(function(){
    $("#popupContainer").empty();
});

这似乎不起作用,我不完全确定如何使这项工作。有没有办法让它的动作aeffect.html可以控制 div index.php

这是完整的jquery:

$(document).ready(function() {
//Find & Open
$(".projectThumb").click(function(){
        $("#popupContainer").load("/aeffect.html");
            });

//Close property
$("a.close").click(function(){
    $("#popupContainer").empty();
        });
});

这是 index.php 的 html

<div id="container">
    <div class="projectThumb">
    <img src="/img/aeffect_button_static.gif" width="146" height="199" class="button" name="aeffect" alt="" />
    <p class="title">A.EFFECT: Film Poster</p>
    </div>
</div>
<div id="popupContainer"></div>

和 aeffect.html 的 html

<div class="projectPopup" id="aeffect">
    <a class="close">Close &times;</a>
    <img src="/img/aeffect_popup.jpg" width="500" height="729" alt="" />
    <p class="description">Description</p>
</div>
4

1 回答 1

3

加载$('a.close').click()处理程序添加到所有a.close元素。这意味着加载的内容中没有附加处理程序。index.phpa.close

在加载新内容后附加处理程序,或$('a.close').live('click', ...)改用。

于 2009-09-09T21:13:11.883 回答