使用Jquery动态设置选项卡标题

时间:2013-04-08 15:53:50

标签: jquery jquery-plugins jquery-easyui

我有一个下拉菜单,有三个标签,

根据我收到的值,我想设置标题和ID,

  <select class="easyui-combobox" name="state" style="width:200px;">
  <option value="DN">Denmark</option>  
  <option value="SG">Singapore</option>  
  <option value="JP">Japan</option>    
    </select> 

如果值为DN则

<div class="easyui-tabs" style="..." >
<div title="Denamrk"><table id="dg1">...</table</div>
<div title="DAN"><table id="dg2">...</table</div>
<div title="Danish Currency"><table id="dg3">...</table</div>
</div>

或者是否可以使用url并从服务器获取标签中的数据? tab或div是否有数据选项?

1 个答案:

答案 0 :(得分:2)

试试这个: -

<强> http://jsfiddle.net/adiioo7/fT5vt/2/

JS: -

var arrValues = {
    "DN": {
        0: "Denmark",
        1: "DAN",
        2: "Danish Currency"
    },
        "SG": {
        0: "Singapore",
        1: "SG",
        2: "SG Currency"
    },
        "JP": {
        0: "Japan",
        1: "JP",
        2: "JP Currency"
    }
};

function updateTabs() {
    var selectedOption = $('#dropdown').combobox('getValue');
    for (var i = 0; i <= 2; i++) {
         var tab = $('#tabs').tabs('getTab',i);
        $('#tabs').tabs('update', {
            tab: tab,
            options: {
                title: arrValues[selectedOption][i]
            }
        });
    }
}

$(function () {
    $('#tabs').tabs();
});

HTML: -

<select id="dropdown" class="easyui-combobox" data-options="  
        onSelect: updateTabs" name="state" style="width:200px;">
    <option value="DN">Denmark</option>
    <option value="SG">Singapore</option>
    <option value="JP">Japan</option>
</select>
<div id="tabs" class="easyui-tabs" style="...">
    <div title="Denmark">
        <table id="dg1">...</table>
    </div>
    <div title="DAN">
        <table id="dg2">...</table>
    </div>
    <div title="Danish Currency">
        <table id="dg3">...</table>
    </div>
</div>