【发布时间】:2012-06-28 08:25:19
【问题描述】:
$(document).ready(function(){
$(function() {
$('a.ajaxload').click(function(e) {
var url = $(this).attr('href');
$('#desktopcontainer').load(url); // load the html response into a DOM element
e.preventDefault(); // stop the browser from following the link
});
});
$(function() {
$(".accordion .accordion-tabs .tab").each(function(){
$(this).click(function(){
if ($(this).hasClass('tab')){
$(this).removeClass('tab');
$(this).addClass('active');
}else{
$(this).removeClass('active');
$(this).addClass('tab');
}
$(this).next().slideToggle('slow');
return false;
});
});
});
});
我的标签工作正常,但是在我单击“a.ajaxload”向页面添加内容后,我的标签不再响应。
谁能告诉我问题出在哪里?
解决了!!!
我所做的是在加载后添加函数……看看下面的新代码,看看有什么不同。我希望它可以帮助某人。
$(document).ready(function(){
initDashboard();
$(function() {
$('a.ajaxload').click(function(e) {
var url = $(this).attr('href');
$('#desktopcontainer').load(url); // load the html response into a DOM element
e.preventDefault(); // stop the browser from following the link
initDashboard();
});
});
function initDashboard() {
$(".accordion .accordion-tabs .tab").each(function(){
$(this).click(function(){
if ($(this).hasClass('tab')){
$(this).removeClass('tab');
$(this).addClass('active');
}else{
$(this).removeClass('active');
$(this).addClass('tab');
}
$(this).next().slideToggle('slow');
return false;
});
});
}
});
【问题讨论】:
-
能否给我们看看你的html代码?
-
也许点击也应该是
live(注意:在jQuery 1.7+中你应该使用on代替)?它加载什么内容?你能发布一个jsfiddle> -
@Phenix 我的 HTML 在页面中,我通过 load(url) 动态获取它们。
-
@Darhazar on() 对我不起作用,我是最新版本的 jQuery。
标签: jquery