0

嗨,我正在使用 jQuery 加载从链接中获取 ahref,然后我想从进入 div 的页面加载 div,所以尝试了这个:

// 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”中的空格,但这没有帮助,任何帮助将不胜感激。

4

1 回答 1

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'); 总是会得到块中的第一个链接,而不是被点击的实际链接。

于 2013-02-15T11:28:12.837 回答