我有這樣的HTML結構:jQuery的,如果HREF ATTR
<ul class="tabs">
<li><a href="#tab1"><h3>Sound</h3><img class="servicesIcon" src="img/micro.png"></img></a></li>
<li><a href="#tab2"><h3>Lighting</h3><img class="servicesIcon" src="img/light.png"></img></a></li>
<li><a href="#tab3"><h3>Staging</h3><img class="servicesIcon" src="img/barstool.png"></img></a></li>
<li><a href="#tab4"><h3>Sales</h3><img class="servicesIcon" src="img/info.png"></img></a></li>
<li><a href="http://www.example.co.uk/" target="_BLANK"><h3>Hire Guide</h3><img class="servicesIcon" src="img/info.png"></img></a></li>
</ul>
與這個jQuery:
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
但我想要做的是,如果 '禮' 被點擊沒有什麼#tab的href然後它只是返回true,並按照正常的鏈接?
感謝,我去了第二個:) – benhowdle89 2011-01-13 15:31:32
@ benhowdie89:不客氣。請記住3,你會得到最慢的性能,因爲它不是一個有效的querySelectorAll選擇器。真的不是太大的交易,因爲這隻會運行一次。 :o) – user113716 2011-01-13 15:33:18