猿问

检查表并根据同一表中两个匹配列的值将 tr 内容加粗

我正在处理响应式表格,并且希望在与当前日期匹配的情况下将行内容设为粗体。

我将第一个孩子 th 和 td 隐藏起来,因为我只需要它来实现某些功能

基于 <td data-label="TodaysDate">06-05-2020</td>和的价值<td data-label="Date">05-05-2020</td>

if value if TodaysDate = Date那么我需要将此行设为粗体。

我怎样才能使用javascript做到这一点

https://codepen.io/KGuide/pen/MWwMZzP

function compareCellValues() {


  var rows = $(".ramadan-time").find("tbody tr"); //returns all table rows


  rows.each(function() { //iterate over each row.


    var thisRow = $(this), //this is the current row

        TodaysDate = thisRow.find(".TodaysDate"), //this is the first value

        sDate = thisRow.find(".Date"); //this is the second value


    if (TodaysDate.text() !== sDate.text()) {

     thisRow.css("font-weight", "bold");

      

    }


    thisRow.find(".TodaysDate").text(parseInt(TodaysDate.text()) - parseInt(sDate.text()));


  });


}


window.onload = compareCellValues();

body {

  font-family: "Open Sans", sans-serif;

  line-height: 1.25;

}

.ramadan-time > thead tr th:first-child{color:red; display:none;}

.ramadan-time > tbody tr td:first-child{color:red; display:none;}

table {

  border: 1px solid #ccc;

  border-collapse: collapse;

  margin: 0;

  padding: 0;

  width: 100%;

  table-layout: fixed;

}



table tr {

  background-color: #f8f8f8;

  border: 1px solid #ddd;

  padding: .35em;

}


table th,

table td {

  padding: .625em;

  text-align: center;

   font-size: 12px;

}


table th {

  font-size: .85em;

  font-size: 12px;

  letter-spacing: .1em;

  text-transform: uppercase;

   white-space: nowrap;

  overflow: hidden;

  text-overflow: ellipsis;

}


@media screen and (max-width: 380px) {

  table {

    border: 0;

  }


  table caption {

    font-size: 1.3em;

  }

  

  table thead {

    border: none;

    clip: rect(0 0 0 0);

    height: 1px;

    margin: -1px;

    overflow: hidden;

    padding: 0;

    position: absolute;

    width: 1px;

  }

  

  table tr {

    border-bottom: 3px solid #ddd;

    display: block;

    margin-bottom: .625em;

  }

  

  table td {

    border-bottom: 1px solid #ddd;

    display: block;

    font-size: .8em;

    text-align: right;

  }

  



POPMUISE
浏览 93回答 1
1回答

繁星点点滴滴

它对我有用,我已将日期放入并6-05-2020与它进行比较06-05-2020修复数据脚本后工作正常。<!DOCTYPE html><html ><head>&nbsp; <meta charset="UTF-8">&nbsp; <title>CodePen - A Pen by&nbsp; KGuide</title>&nbsp; <link rel="stylesheet" href="./style.css"></head><body><!-- partial:index.partial.html --><table class="ramadan-time">&nbsp; <thead>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <th scope="col">TodaysDate</th>&nbsp; &nbsp; &nbsp; <th scope="col">Date</th>&nbsp; &nbsp; &nbsp; <th scope="col">Day</th>&nbsp; &nbsp; &nbsp; <th scope="col">Ramadan</th>&nbsp; &nbsp; &nbsp; <th scope="col">April/May</th>&nbsp; &nbsp; &nbsp; <th scope="col">Imsak</th>&nbsp; &nbsp; &nbsp; <th scope="col">Fajr</th>&nbsp; &nbsp; &nbsp; <th scope="col">Sunrise</th>&nbsp; &nbsp; &nbsp; <th scope="col">Dhuhr</th>&nbsp; &nbsp; &nbsp; <th scope="col">Asr</th>&nbsp; &nbsp; &nbsp; <th scope="col">Maghrib</th>&nbsp; &nbsp; &nbsp; <th scope="col">Isha</th>&nbsp; &nbsp; </tr>&nbsp; </thead>&nbsp; <tbody>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td class="TodaysDate" data-label="TodaysDate">06-05-2020</td>&nbsp; &nbsp; &nbsp; <td class="Date" data-label="Date">05-05-2020</td>&nbsp; &nbsp; &nbsp; <td data-label="Day">Friday</td>&nbsp; &nbsp; &nbsp; <td data-label="Ramadan">1</td>&nbsp; &nbsp; &nbsp; <td data-label="April/May">24</td>&nbsp; &nbsp; &nbsp; <td data-label="Imsak">4:17</td>&nbsp; &nbsp; &nbsp; <td data-label="Fajr">4:27</td>&nbsp; &nbsp; &nbsp; <td data-label="Sunrise">5:45</td>&nbsp; &nbsp; &nbsp; <td data-label="Dhuhr">12:20</td>&nbsp; &nbsp; &nbsp; <td data-label="Asr">3:49</td>&nbsp; &nbsp; &nbsp; <td data-label="Maghrib">6:49</td>&nbsp; &nbsp; &nbsp; &nbsp;<td data-label="Isha">8:07</td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; &nbsp;<tr>&nbsp; &nbsp; &nbsp; <td class="TodaysDate" data-label="TodaysDate">06-05-2020</td>&nbsp; &nbsp; &nbsp; <td class="Date" data-label="Date">06-05-2020</td>&nbsp; &nbsp; &nbsp; <td data-label="Day">Saturday</td>&nbsp; &nbsp; &nbsp; <td data-label="Ramadan">2</td>&nbsp; &nbsp; &nbsp; <td data-label="April/May">25</td>&nbsp; &nbsp; &nbsp; <td data-label="Imsak">4:16</td>&nbsp; &nbsp; &nbsp; <td data-label="Fajr">4:26</td>&nbsp; &nbsp; &nbsp; <td data-label="Sunrise">5:44</td>&nbsp; &nbsp; &nbsp; <td data-label="Dhuhr">12:20</td>&nbsp; &nbsp; &nbsp; <td data-label="Asr">3:50</td>&nbsp; &nbsp; &nbsp; <td data-label="Maghrib">6:49</td>&nbsp; &nbsp; &nbsp; &nbsp;<td data-label="Isha">8:08</td>&nbsp; &nbsp; </tr>&nbsp; &nbsp; <tr>&nbsp; &nbsp; &nbsp; <td class="TodaysDate" data-label="TodaysDate">06-05-2020</td>&nbsp; &nbsp; &nbsp; <td class="Date" data-label="Date">07-05-2020</td>&nbsp; &nbsp; &nbsp; <td data-label="Day">Sunday</td>&nbsp; &nbsp; &nbsp; <td data-label="Ramadan">3</td>&nbsp; &nbsp; &nbsp; <td data-label="April/May">26</td>&nbsp; &nbsp; &nbsp; <td data-label="Imsak">4:15</td>&nbsp; &nbsp; &nbsp; <td data-label="Fajr">4:25</td>&nbsp; &nbsp; &nbsp; <td data-label="Sunrise">5:43</td>&nbsp; &nbsp; &nbsp; <td data-label="Dhuhr">12:19</td>&nbsp; &nbsp; &nbsp; <td data-label="Asr">3:48</td>&nbsp; &nbsp; &nbsp; <td data-label="Maghrib">6:50</td>&nbsp; &nbsp; &nbsp; &nbsp;<td data-label="Isha">8:10</td>&nbsp; &nbsp; </tr>&nbsp;&nbsp; </tbody></table>
随时随地看视频慕课网APP

相关分类

Html5
我要回答