防止切换时动态内容丢失

发布于 2024-12-19 21:09:07 字数 529 浏览 2 评论 0原文

我正在从服务器检索一些数据并更新 div 的 html 内容,如下所示:

var req = new Request.JSON({
    method: 'get',
    url: 'index.php',
    data: {},
    onSuccess: function(r) {
        $('my_div').set('html',r.output);
        }
    }
});

我希望也能够“切换”结果,我使用这个:

var mySlide = new Fx.Slide('my_div');
$('toggle_link').addEvent('click', function(event){
    event.stop();
    mySlide.toggle();
    event.stop();
}); 

这可能只工作一次,因为 html 内容是动态检索。有没有办法防止丢失 Div 中的 html 内容并显示切换效果?

谢谢!

I am retrieving some data from the server and update the html contents of a div like this:

var req = new Request.JSON({
    method: 'get',
    url: 'index.php',
    data: {},
    onSuccess: function(r) {
        $('my_div').set('html',r.output);
        }
    }
});

I wish to be able to 'toggle' the results as well and I use this:

var mySlide = new Fx.Slide('my_div');
$('toggle_link').addEvent('click', function(event){
    event.stop();
    mySlide.toggle();
    event.stop();
}); 

This works only once presumably due to the fact that html contents are retrieved dynamically. Is there a way to prevent loosing the html contents from my Div and show the toggle effect?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮云落日 2024-12-26 21:09:07

要解决高度问题,您需要为 Fx.Slide 设置 resetHeight: true 选项。 此处更新了示例。

To solve the problem about height, you need to set the resetHeight: true option to your Fx.Slide. Updated example here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文