七度&光 2012-09-23 18:47 采纳率: 22.2%
浏览 78

jQuery和Ajax:显示/隐藏div

I have this example.

When I click, a dynamic content load via Ajax. In the loaded page there is a link, that could close the div. It works, but when the div is closed (with hide()), the click on link don't reopen loaded page.

Why? How can I create a button, that show/hide a div loaded with Ajax?

Calling page :

<script type="text/javascript">
function getAjax(divdett,pageload) {
$(function(){$(divdett).load(pageload);});}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>click</title>
</head>
<body>
<a href="javascript:getAjax('#siteloader','jquery_divajax.htm');">click</a>
<div id="siteloader"></div>
</body>

Included page :

<script type="text/javascript">
function delAjax(divdett) {
$(divdett).hide();
}
</script>
OK!
<a id="#chiudi" href="#" onclick="delAjax('#siteloader');">chiudi</a>
  • 写回答

4条回答 默认 最新

  • weixin_33725270 2012-09-23 18:49
    关注

    In your "close" button, you call hide().

    Change your getAjax function to this :

    function getAjax(divdett,pageload) {
    $(function(){$(divdett).load(pageload).show();});}
    

    I just added .show() to ensure the div is visible even if it has been made hidden before.

    Note that I respected the original construct but this is much too complex : no need to call $(function when you can simply do

    function getAjax(divdett,pageload) {
    $(divdett).load(pageload).show();}
    

    If you want to have only one button, you may remove the one of the second file and change the getAjax function to

    function getAjax(divdett,pageload) {
         var div = $(divdett);
         if (div.is(':visible')) div.hide();
         else div.load(pageload).show();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置