$(this).finden("a").attr("onclick"); onclick Angabe ungültige Zeichen

I m, erstellen eine dynamische tab mit Jquery seine arbeiten fein, aber gibt Fehler für Anker-tag onclick Fehler ist ungültiges Zeichen.
Siehe javascript:

$(document).ready(function(){

    //when page loads...
    $(".tab_content").hide(); //hide all content
    $("ol.tabs li:first").addClass("active").show();  //Activate first tab
    $(".tab_content:first").show(); //show first tab content

    //on click event
    $("ol.tabs li").click(function(){
        $("ol.tabs li").removeClass("active"); //remove any "active" class
        $(this).addClass("active"); //add "active" class to selected tabs
        $(".tab_content").hide(); //hide all tab content
        //var activeTab = $(this).find("a").attr("href"); //find href attribute value to identify the active tab + content
        var activeTab = $(this).find("a").attr("onclick"); //find href attribute value to identify the active tab + content
        $(activeTab).fadeIn(); //fadeIn the active ID content
        alert(activeTab);
        return false;
    });

});

Und HTML:

<div>
    <div id="tab1" class="tab_content">01</div>
    <div id="tab2" class="tab_content">02</div>
    <div id="tab3" class="tab_content">03</div>
</div>
<ol class="tabs">
    <li><a onclick="#tab1">Unique benefits</a></li>
    <li><a onclick="#tab2">Insurance</a></li>
    <li><a onclick="#tab3">Business Loan</a></li>
</ol>

Wenn ich var activeTab = $(this).find("a").attr("href");

Seine Arbeit in Ordnung.
Helfen

warum sind Sie auf der Suche nach der onclick - Attribut? Was versuchen Sie zu erreichen?
Ihre HTML scheint ungültig, Sie haben eine extra </div>. Außerdem haben Sie versucht, jquery ui tabs?
Wenn .attr( "href" ) funktioniert, warum nicht?

InformationsquelleAutor Sagar | 2011-08-18

Schreibe einen Kommentar