幾乎解決了這個問題,但似乎我不允許與jQuery「a []」標記內的變量匹配。我試圖用的顯示活動/非活動狀態,當用戶點擊地圖上的相應區域的鏈接列表連接的交互式地圖 -找到並添加/刪除鏈接與匹配的rel值
// Inside a click event with var active containing the fetch from the map
var active = "Lorem ipsum";
if($('a[rel^=' + active + ']', '.regions')) {
if ($('a[rel^=' + active + ']', '.regions').hasClass('active')) {
$('a[rel^=' + active + ']', '.regions').removeClass('active');
}
else {
$('a[rel^=' + active + ']', '.regions').addClass('active');
}
}
對不起,我誤解你的代碼,你也解決了它。謝謝! – 2012-01-02 01:38:57