【问题标题】:tabs container property change using jquery使用 jquery 更改选项卡容器属性
【发布时间】:2018-04-27 03:03:27
【问题描述】:

我想更改被检查代码的属性

<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 顶点。我对 jquery 和 js 的了解较少。我该怎么做?

【问题讨论】:

  • 我建议您通过简单地澄清您想要更改的内容和位置来改进您的问题,例如:“将“a-Tabs-before”类添加到a-Tabs-panel”元素等。直接并避免了“发现差异”的需要。看来您应该研究 .addClass() 方法 - 参见: api.jquery.com/addclass

标签: javascript jquery html css oracle-apex


【解决方案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";
    }   

【讨论】:

  • 您的答案似乎不完整,也可以通过syntax highlighting 受益
【解决方案2】:

你可以使用以下方法在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");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多