使用jquery选项卡容器属性更改

时间:2017-11-14 08:40:49

标签: javascript jquery html css oracle-apex

我想更改所需代码的属性

<li id="SR_R1_tab" class="t-Tabs-item a-Tabs-selected is-active" aria-controls="SR_R1" role="tab" aria-selected="false">
  <a class="t-Tabs-link" href="#SR_R1" role="presentation" tabindex="-1">
    <span>1<span>
  </a>
</li>

<div id="SR_R1" class="a-Tabs-panel a-Tabs-before" data-label="1" role="tabpanel" aria-labelledby="SR_R1_tab" aria-hidden="true" style="display: block;" >

<li id="SR_R1_tab" class="t-Tabs-item a-Tabs-before a-Tabs-selected is-active" aria-controls="SR_R1" role="tab" aria-selected="true"> 
<a class="t-Tabs-link" href="#SR_R1" role="presentation" >
    <span>1<span>
  </a>
</li>

<div id="SR_R1"  class="a-Tabs-panel a-Tabs-before a-Tabs-element-selected" data-label="1" role="tabpanel" aria-labelledby="SR_R1_tab" aria-hidden="false" style="display: block;" >

使用js函数或jquery。我正在使用oracle apex。我对jquery和js的了解较少。我怎么能这样做?

2 个答案:

答案 0 :(得分:1)

Please Try below javascript.

1. Add the style first

    div.tab {
        overflow: hidden;
        border: 1px solid #ccc;
        background-color: #f1f1f1;
    }    
    div.tab button {
        background-color: inherit;
        float: left;
        border: none;
        outline: none;
        cursor: pointer;
        padding: 14px 16px;
        transition: 0.3s;
        font-size: 17px;
    }    
    div.tab button:hover {
        background-color: #ddd;
    }
    div.tab button.active {
        background-color: #ccc;
    }    
    .tabcontent {
        display: none;
        padding: 6px 12px;
        border: 1px solid #ccc;
        border-top: none;
    }

2. Copy and paste below HTML

 <div class="tab">
              <button class="tablinks" onclick="openCity(event, 'London')">London</button>
              <button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
              <button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
            </div>

            <div id="London" class="tabcontent">
              <h3>London</h3>
              <p>London is the capital city of England.</p>
            </div>

            <div id="Paris" class="tabcontent">
              <h3>Paris</h3>
              <p>Paris is the capital of France.</p> 
            </div>

            <div id="Tokyo" class="tabcontent">
              <h3>Tokyo</h3>
              <p>Tokyo is the capital of Japan.</p>
            </div>

3. Add below script in your webpage.

    function openCity(evt, cityName) {
        var i, tabcontent, tablinks;
        tabcontent = document.getElementsByClassName("tabcontent");
        for (i = 0; i < tabcontent.length; i++) {
            tabcontent[i].style.display = "none";
        }
        tablinks = document.getElementsByClassName("tablinks");
        for (i = 0; i < tablinks.length; i++) {
            tablinks[i].className = tablinks[i].className.replace(" active", "");
        }
        document.getElementById(cityName).style.display = "block";
        evt.currentTarget.className += " active";
    }   

答案 1 :(得分:1)

您可以使用以下方法在js中设置/更改属性

document.getElementById('yourElementId').setAttribute("propertyName","propertyValue");

例如:

 document.getElementById('SR_R1_tab').setAttribute("class","t-Tabs-item a-Tabs-before a-Tabs-selected is-active");