2

I have thee tabs in sj:tabbedpanel. I want to know which tab is activated and set values in value of a hidden field accordingly.

<sj:tabbedpanel id="localtabs" >                
   <sj:tab id="connected" target="tone" label="Connected" />
    <sj:tab id="disconnected" target="ttwo" label="Not Connected"/>
    <sj:tab id="distribution" target="tthree" label="Distributed"/>
    <div id="tone">tone</div>
    <div id="ttwo">ttwo</div>
    <div id="tthree">tthree</div>    
</sj:tabbedpanel>

Now I want to set value of hidden input field according to activated tab 0,1 or2 for tabs tone, ttwo and tthree.

<input type="hidden" name="activeTab" value="0" id ="activeTab"/>

I tried

$("#connected").click(function(){
    alert("Connected");
    $("#activeTab").val(0);
});
$("#disconnected").click(function(){
    alert("Not Connected");
    $("#activeTab").val(1);
});
$("#distribution").click(function(){
    alert("distribution");
    $("#activeTab").val(3);
});

but its not working. Thanks in advance.

4

1 回答 1

2

订阅onchange主题

<sj:tabbedpanel id="localtabs" onChangeTopics="tabchange" >
    <sj:tab id="connected" target="tone" label="Connected" />
    <sj:tab id="disconnected" target="ttwo" label="Not Connected"/>
    <sj:tab id="distribution" target="tthree" label="Distributed"/>
    <div id="tone">tone</div>
    <div id="ttwo">ttwo</div>
    <div id="tthree">tthree</div>
</sj:tabbedpanel>

并处理事件

$.subscribe('tabchange', function(event, data) {
    var tab = event.originalEvent.ui.newTab.attr("id");
    if (tab === "connected") {
        $("#activeTab").val(0);
    } else if (tab === "disconnected") {
        $("#activeTab").val(1);
    } else if (tab === "distribution") {
        $("#activeTab").val(3);
    }
});
于 2013-09-10T14:42:05.220 回答