$(function() {
$(".dijit").live("click", function() {
$(".dijit").removeClass("active"); // remove active class from all
$(this).addClass("active"); // add active class to clicked element
$("#dijit_utm").load('index.html');
});
});
使用这种方法将意味着在同一个页面加载的每个环节。如果您需要加载每个项目的网页,然后将下面的代码会更加容易:
HTML
<div class="dijit active" id="dijit_dashboard"><a href="dashboard.html">Dashboard</a></div>
<div class="dijit" id="dijit_pages"><a href="pages.html">Pages</a></div>
jQuery的
$(function() {
$(".dijit").live("click", function(e) {
e.preventDefault();
$(".dijit").removeClass("active"); // remove active class from all
$(this).addClass("active"); // add active class to clicked element
var href = $(this).find("A").attr("href");
$("#dijit_utm").load(href);
});
});
UPDATE
这个古老的答案似乎仍得到相当稳定的看法,所以这里采用了最新的jQuery方法更新的答案live()
已经从1.7版本弃用:
$(document).on('click', '.dijit', function(e) {
e.preventDefault();
var $el = $(this);
$el.addClass("active").siblings().removeClass('active');
$("#dijit_utm").load($el.find('a').attr('href'));
});
我可以尝试使用变量来提取数据 – 2011-04-28 15:37:57