1
我有一個頁面發出一個AJAX請求,並從數據庫中返回一些數據,一旦它被重新創建,我試圖將它附加到一個div並製作一個手風琴,但是我所得到的是把數據傳回,在這裏沒有手風琴是我的源代碼一旦AJAX已經用完。(片段)DOM,Jquery和Accordions
<script type="text/javascript">
$(document).ready(function() {
//accordians for when the AJAX loads the content
// hides the main_menu as soon as the DOM is ready
// (a little sooner than page load)
$('#main_menu').hide();
// shows the slickbox on clicking the noted link
$('h3#show-menu a').click(function() {
$('#main_menu').toggle('slow');
return false;
});
//try and hide the left content when it is null
$("#left-content:empty").hide();
//style up the scroll bar
$('#left-content').jScrollPane();
//do some AJAX to call the method instead of the browser
$("a.navlink").click(function (ev) {
$(this).toggleClass("active");
ev.preventDefault();
var id = $(this).attr("id")
if ($(this).hasClass("active")) {
$("."+id).remove();
} else {
//$(this).toggleClass("active");
var url = $(this).attr("href");
$.ajax ({
url: url,
type: "POST",
success : function (html) {
$("#accordion").append(html);
$('#accordion').accordion({
active: 0,
header:'h2.Blog'
});
//alert(accordion())
}
});
}
});
});
</script>
</head>
<body>
<div style="left: -100em; position: absolute; width: 100em;"/>
<div id="wrapper">
<h3 id="show-menu">
</h3>
<div id="main_menu" style="display: block;">
</div>
<div id="left-content-holder">
</div>
<div id="right-content">
<div id="accordion" class="ui-accordion ui-widget ui-helper-reset" role="tablist">
<h2 class="Blog ui-accordion-header ui-helper-reset ui-state-active ui-corner-top" role="tab" aria-expanded="true" tabindex="0">
</h2>
<div class="Blog ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom ui-accordion-content-active" style="height: 16px;" role="tabpanel">Hello World</div>
</div>
</div>
</div>
正如你可以看到數據被追加到<div id="accordion">
和所有的apropriate類得到給予元素應該給它手風琴的功能,但我什麼也得不到。我應該從DOM創建手風琴,理論上返回的數據不在HTML中,如果是的話,我該如何去做這件事?
謝謝
你絕對真實,我可以吻你! – Udders 2009-12-11 00:00:28
輕鬆。你必須先吸引我,哈哈。很高興它的工作;) – munch 2009-12-11 07:45:37