javascript - 我如何使用 javascript 添加 attr

标签 javascript jquery

如何使用 javascript 添加属性:

代码如下:

<ul class="nav nav-tabs">
  <li class="active">
    <a href="#tab_1_4" data-toggle="tab" id="8" onclick="TableIdByNew(this.id)"><span class="badge badge-default" id="sipp-count">0</span> New </a>

  </li>
  <li>
    <a href="#tab_1_2" data-toggle="tab" id="9" onclick="TableIdByInProgress(this.id)"><span class="badge badge-default" id="sass-count">0</span> InProgress </a>
  </li>
  <li>
    <a href="#tab_1_3" data-toggle="tab" id="10" onclick="TableIdByClosed(this.id)"><span class="badge badge-default" id="sass-counts">0</span> Closed </a>
  </li>
</ul>

我想添加:

  $("8").attr("aria-expanded", "true");
  $("9").attr("aria-expanded", "false");
  $("10").attr("aria-expanded", "false");

但这行不通。

这是表格:

<div class="tab-pane active in" id="tab_1_4" style="display:none">
                        <p>
                            <div class="portlet box">
                                <div class="portlet-title">


                                    <table class="table table-striped table-bordered dt-responsive table-hover" width="100%" id="AdminTicketId4" cellspacing="0">
                                        <thead>


                                            <tr>
                                                <th> Date Created </th>
                                                <th> Title </th>
                                                <th> User Name </th>
                                                <th> User Email </th>
                                                <th> Assigned To </th>
                                                <th>Importancy</th>
                                                <th> Status </th>
                                            </tr>
                                        </thead>

                                    </table>

                                </div>
                            </div>
                        </p>
                    </div>

表格在这里:

这是第一张 table 好吗。

我该如何解决??

哪里错了???

最佳答案

jQuery 选择器的工作方式类似于 CSS 选择器。

要通过 ID (this_is_an_id) 选择元素,请使用 $('#this_is_an_id')。注意 # - 没有它,您将匹配 this_is_an_id 类型的元素。将 $('li') 视为一个有意义的示例。

关于javascript - 我如何使用 javascript 添加 attr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43535799/

相关文章:

javascript - 如何在 JavaScript 中更改 Bootstrap 弹出窗口的颜色

javascript - 如何让对象返回一个不是对象本身的值

javascript - React 不允许我使用 React.Fragment

javascript - 如何在揭示原型(prototype)模式中命名对象?

javascript每次覆盖数组对象

jquery - 如何修复左列数据表,如示例所示

javascript - 如何自定义这个已经自定义的 jQuery 排序解决方案?

jQuery UI 可排序排序动态添加的新 ul

javascript - 如何使用 javascript 关闭当前选项卡?

javascript - nodejs以数组格式追加到json文件中