我想顯示搜索旁邊的總行數,并使搜索代碼在python中工作?

我創建了一個表,我想搜索兩列(代碼和名稱),所以當用戶輸入任何字母或名稱、代碼列時,它會顯示包含該字母的所有行名,我想在搜索框旁邊顯示我的表的總行數。

in HTML

 <input type="text" class="form-control"  onkeyup="searchrecords" id="searchtext" placeholder="Search" aria-label="Text input with dropdown button">
                                        <h6 class="mt-3 mx-4">Total: </h6>
                                    </div>
                                </div>
                                <table class="table table-striped " id="table1">
                                    <thead>
                                        <tr class="feed-bg text-white ">
                                            <th>ID</th>
                                            <th>Employee Code</th>
                                            <th>Employee Name</th>
                                            <th>Email</th>

                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for i in data_list %}
                                        <tr>
                                            <td>{{ forloop.counter }}</td>
                                            <td>{{i.employee_code}}</td>
                                            <td>{{i.employee_name}}</td>
                                            <td>{{i.email}}</td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>

在JS中,我做了搜索代碼,但它不起作用!

   function searchrecords()
   {
       var input,table,tr,td,filter;
       input=document.getElementById("searchtext");
       filter=input.value.toUpperCase();
       table=document.getElementById("table1");
       tr=table.getElementsByTagName("tr");
       for(i=0;i<tr.length;i++)
       {
           td=tr[i].getElementsByTagName("td")[0];
           if(td)
           {
               textdata=td.innerText;
               if(textdata.toUpperCase().indexOf(filter)>-1)
               {
                   tr[i].style.display="";
               }
               else
               {
                   tr[i].style.display="none";
               }
           }
       }
   }

? 最佳回答:

我在這里為你樹立了一個榜樣。也許會有幫助。

const input = document.getElementById("searchtext");
const rowNum = document.getElementById("row-num");
const table = document.getElementById("table1");
const tr = Array.from(table.getElementsByTagName("tr"));

function renderRowNr() {
  rowNum.innerHTML = tr.filter((row) => row.style.display !== "none").length;
}

function resetRows() {
  tr.forEach((row) => (row.style.display = "inherit"));
}

function searchrecords() {
  resetRows();
  input.value &&
    tr
      .filter((row) => {
        return !Array.from(row.children)
          .map((cell) => {
            return cell.textContent
              .toUpperCase()
              .includes(input.value.toUpperCase());
          })
          .some((cell) => cell === true);
      })
      .forEach((row) => (row.style.display = "none"));
  renderRowNr();
}

function init() {
  resetRows();
  renderRowNr();
  input.addEventListener("change", () => searchrecords());
}

init();
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <label>Filter: </label>
    <input id="searchtext" />
    <p>row number: <span id="row-num"></span></p>
    <table class="table table-striped" id="table1">
      <tbody>
        <tr>
          <td>1</td>
          <td>abc</td>
          <td>Lokrum</td>
          <td>email1</td>
        </tr>
        <tr>
          <td>2</td>
          <td>def</td>
          <td>Lara</td>
          <td>email2</td>
        </tr>
        <tr>
          <td>3</td>
          <td>ghi</td>
          <td>Lora</td>
          <td>email3</td>
        </tr>
      </tbody>
    </table>
    <script src="app.js"></script>
  </body>
</html>

主站蜘蛛池模板: 国产在线观看一区二区三区| 一区二区中文字幕在线观看| 亚洲综合在线成人一区| 高清一区二区在线观看| 日本精品少妇一区二区三区| 少妇特黄A一区二区三区| 亚洲国产成人精品无码一区二区| 国产suv精品一区二区6| 亚洲变态另类一区二区三区| 在线精品一区二区三区电影| 高清一区二区在线观看| 精品亚洲AV无码一区二区三区| 亚洲av无码一区二区三区天堂| 国产色欲AV一区二区三区| 日韩在线视频不卡一区二区三区| 精品国产一区二区三区四区 | 免费视频精品一区二区三区| 精品福利一区二区三| 韩国福利一区二区三区高清视频| 亚洲福利一区二区| 91久久精品一区二区| 成人区精品一区二区不卡亚洲 | 搡老熟女老女人一区二区| 国产精品视频一区麻豆| 久久精品无码一区二区无码| 色偷偷久久一区二区三区| 亚洲中文字幕在线无码一区二区| 久久一区二区三区精品| 国产av夜夜欢一区二区三区| 免费无码一区二区三区蜜桃大 | 精品一区二区三区东京热| 久久精品午夜一区二区福利| 亚洲中文字幕一区精品自拍| 性色av无码免费一区二区三区| 中文字幕一区二区三| 亚洲日韩精品无码一区二区三区| 日韩色视频一区二区三区亚洲| 日韩色视频一区二区三区亚洲| 日韩社区一区二区三区| 久久国产高清一区二区三区| 日韩一区在线视频|