重新加载部分ajax页面后,jQuery手风琴损坏

编程入门 行业动态 更新时间:2024-10-27 06:24:28
本文介绍了重新加载部分ajax页面后,jQuery手风琴损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用jquery手风琴,它在初始页面加载时可以正常工作,但是随后我有一些ajax命令可以重新加载页面的一部分,本质上是页面的内部主体.

I am using jquery accordion and it works fine on initial page load, but then I have some ajax commands that reload part of the page, essentially the inner body of the page.

这种情况发生时,手风琴坏掉了,因为我进行的重装工作只是替换了几乎整个body字段的innerHTML.

When this happens, the accordion is broken, since the reload i do is just replacing the innerHTML of almost the entire body field.

替换后的HTML中也包含了加载手风琴的脚本,但这显然无济于事.

The script that loads the accordion is also included in the replaced HTML, but obviously that doesn't help.

替换整个页面的innerHTML之后,如何保持(或重新调用)手风琴效果?

How can I keep (or reinvoke) the accordion effect after replacing the innerHTML of my entire page?

<div class="art-Post-inner" id="ajaxWrapper"> <div id="accordion"> <h3><a href="#">Skärm 1</a></h3> <div> my accordion content </div> </div> <script> $(document).ready(function() { $( '#accordion' ).accordion({ collapsible: true, active: false, autoHeight: false }); }); </script>

通过设置id = ajaxWrapper设置div的innerHTML,这完全被替换了.

This is the art that gets replaced entirely by setting the innerHTML of the div with id=ajaxWrapper.

我相信您会看到问题.

推荐答案

将jquery手风琴函数放入.ajax请求的成功回调中:

Put the jquery accordion function in the success callback of the .ajax request:

示例:

var accordionOpts = { collapsible: "true", active: "false", autoHeight: "false" }; $('#accordion').accordion(accordionOpts); $("#replaceContent").click(function() { $.ajax({ type: 'POST', cache: false, data: { html: "<div id='accordion'><h3><a href='#'>Skärm 2</a></h3><div>my accordion content</div></div>" }, url: '/echo/html/', success: function(data) { $(".art-Post-inner").html(data); $('#accordion').accordion(accordionOpts); } }); });

提琴: jsfiddle/6Scgc/3/

更多推荐

重新加载部分ajax页面后,jQuery手风琴损坏

本文发布于:2023-11-24 22:36:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627152.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:手风琴   加载   页面   ajax   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!