我有一个问题,当通过AJAX从另一个页面接收内容时,手风琴不工作。THe页面是这样的:http://jbm.utad.pt/testes/tempo/index.php
页面一加载,它就会将一个默认的城市名称发送给processtempo.php,后者使用AJAX将结果返回到一个div:
在processtempo.php中,我有一个用于手风琴的超文本标记语言,但它的jQuery是在index.php中。这个手风琴不工作是因为超文本标记语言必须在主页上,还是我搞砸了jQuery?
您可以在源代码中查看accordion jQuery脚本...我还没有把它放到特定的js文件中。
非常感谢所有可能的帮助,并为这个模糊的问题道歉
干杯
发布于 2012-05-08 20:40:46
您将为.tempo-head
分配一个click()
事件,并在ajax例程将元素加载到页面之前对元素执行一系列其他操作。
您需要获得最新版本的JQuery才能运行以下内容。我注意到你现在有一个过时的版本(1.4.2)
尝试更改此设置:
$('.tempo-head').click(function () {
至
$('#sidebar').on('click', '.tempo-head').click(function () {
或
将所有的accordion例程移到ajax调用中的success
回调中,如下所示。
$(document).ready(function(){
var cidade2='penafiel';
var dataString = 'cidade='+ cidade2;
$.ajax({ type: "POST", url: "processtempo.php", data: dataString, cache: false,
success: function(html){
$("#exibe_tempo").html(html);
}
});
$(".cidade").change(function(){
var cidade=$(this).val();
var dataString = 'cidade='+ cidade;
$.ajax({ type: "POST", url: "processtempo.php", data: dataString, cache: false,
success: function(html){
$("#exibe_tempo").html(html);
//Add Inactive Class To All Accordion Headers
$('.tempo-head').toggleClass('head-off');
//Set The Accordion Content Width
var contentwidth = $('.tempo-head').width();
$('.tempo-cont').css({'width' : contentwidth });
//Open The First Accordion Section When Page Loads
//$('.tempo-head').first().toggleClass('head-on').toggleClass('head-off');
//$('.tempo-cont').first().slideDown().toggleClass('tempo-cont');
// The Accordion Effect
$('.tempo-head').click(function () {
if($(this).is('.head-off')) {
$('.head-on').toggleClass('head-on').toggleClass('head-off').next().slideToggle().toggleClass('tempo-cont');
$(this).toggleClass('head-on').toggleClass('head-off');
$(this).next().slideToggle().toggleClass('tempo-cont');
}
else {
$(this).toggleClass('head-on').toggleClass('head-off');
$(this).next().slideToggle().toggleClass('tempo-cont');
}
});
}
});
});
return false;
}); // END DOC READY
https://stackoverflow.com/questions/10451640
复制相似问题