2013-02-15 71 views
0

嗨,我使用jQuery負荷抓住從一個鏈接AHREF,然後我想從加載網頁IM進入一個div等等都試過這一個div:jQuery的負載變量將不會加載內容

// lets load the contents 
$('#navigationLinks a:not(:first-child)').click(function(event){ 

    $('#wrapper').animate({ 
     'left':'0px' 
    }); 

    var href = $('#navigationLinks a').attr('href'); 
    $('#content').load(href + ' #resultDiv'); 

    event.preventDefault(); 

}); 

這是HTML:

<div id="navigationLinks"> 
    <a href="index.html" id="dashboardHome">Dashboard Home</a> 
    <a href="industry-overview.html" title="Industry Overview" class="first currentLink">Industry Overview</a> 
    <a href="regions.html" title="Regions">Regions</a> 
    <a href="industries.html" title="Industries">Industries</a> 
    <a href="security-pipeline.html" title="Security Pipeline">Security Pipeline</a> 
    <a href="audit-events-issues.html" title="Audit Events &amp; Issues">Audit Events &amp; Issues</a> 
    <a href="account-filter.html" title="Account Filter">Account Filter</a> 
    <a href="contractual-delivered-services.html" title="Contractual vs. Delivered Services" class="last">Contractual vs. Delivered Services</a> 
</div> 

我試過#前「#resultDiv」去掉空間,但沒有幫助,任何幫助將不勝感激。

+0

對不起,我不知道答案,但你可以console.log()並確認所有的作品正在工作:1.事件正在發射2. href是有效的3.該查詢#content正在返回的東西? 請注意,您可以使用'var href = jQuery(this).attr('href');'。更高效。 – spinkus 2013-02-15 10:57:43

回答

1

你應該試試這個

$(document).ready(function(){ 

$('#navigationLinks a:not(:first-child)').click(function(e){ 
    var href = e.target; 
    $('#content').load(href + ' #resultDiv'); 
    e.preventDefault(); 

}); 
}); 

的問題是,var href = $('#navigationLinks a').attr('href');總是會得到該塊中的第一個環節,而不是實際鏈接被點擊。

+0

var href = e.target; - 通過加載帶有id的resultDiv的div中的url無效 – user1338176 2013-02-15 12:37:03