jquery - 返回 "previous function"

标签 jquery ajax forms function

我有这个脚本:

$('#ap').click(function() {
   $('#content-container').html($('#alertpay').html());
    return false;
});

每当有人点击#ap时,就会在#content-container中显示#alertpay的内容。

但是,我如何才能创建返回链接,以便当用户单击它时,它将显示 #content-container 中的原始内容? (那里的内容。)

更新 我正在尝试使用这段代码:

                    <div align="center" id="content-container">
                        <a href="#" id="ap">Show #alertpay</a> 
                    </div>

  <div id="alertpay" style="display:none">
    #alertpay content here.

      <a href="#" id="return-link">RETURN</a>

    </div>


(function(){
    var cchtml;
    $('#ap').click(function(){
       cchtml = $('#content-container').html();
       $('#content-container').html($('#alertpay').html());
       return false;
    });

    $('#return-link').click(function(){
       $('#content-container').html(cchtml);
       return false;
    });
})();

这里不起作用的是当我按下 RETURN anchor 链接时。它没有做任何事情。

最佳答案

最好的选择是拥有三个容器。一开始是空的。根据用户行为选择要显示的内容。

$('#ap').click(function() {
   $('#empty-container').html($('#alertpay').html());
    return false;
});

$('#revert-ap').click(function() {
   $('#empty-container').html($('#content-container').html());
    return false;
});

并确保隐藏内容容器和alertpay

关于jquery - 返回 "previous function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7220047/

相关文章:

javascript - Jquery - 从元素中删除类后仍处于事件状态

jquery - 如何使用jquery ui slider 创建分页效果并加载<DIV>中的内容?

php - Select2 未通过 POST 提交

Django 表单choicefield 自动生成选择

javascript - 在 AppBrowser 中以编程方式更改 selectMenu 选项

jquery - 悬停时将一个 div 替换为另一个

javascript - jQuery 替换鼠标光标

javascript - 为什么我的 javascript ajax 调用有它需要的数据但谷歌图表没有

javascript - 如何在 AJAX 之后更新 Facebook/Twitter 分享按钮 URL?

javascript - Chrome form.submit() 处理程序忽略必填字段