如何比较两列的值,然后根据循环中的比较更改文本

发布于 2024-10-31 13:11:29 字数 228 浏览 0 评论 0原文

我需要遍历数据网格的循环,将值column1.cell1与column2.cell1进行比较,然后将column1.cell2与column2.cell2等进行比较...并根据比较显示第一列中带有文本的图像,

我应该首先需要将两列的值放入两个数组中进行比较?或者应该是什么代码

$('#dataGrid tr th').each(function() {
   ??
});

I need to go through loop for data grid, compare values column1.cell1 with column2.cell1 and then column1.cell2 with column2.cell2 and so on... and based on comparison show an image with text in first column

should I first need to put values of two columns in two arrays to compare? Or what should be code

$('#dataGrid tr th').each(function() {
   ??
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

压抑⊿情绪 2024-11-07 13:11:29
$('#dataGrid tr').each(function() {
    var cell1 = $('td:nth-child(1)', this);
    var cell2 = $('td:nth-child(2)', this);

    //Comparison here???
});
$('#dataGrid tr').each(function() {
    var cell1 = $('td:nth-child(1)', this);
    var cell2 = $('td:nth-child(2)', this);

    //Comparison here???
});
咋地 2024-11-07 13:11:29

试试这个。给出的例子可能对你有帮助。

HTML:

<table cellspacing="0" rules="all" border="1" id="gvCommentSample" style="width:30%;border-collapse:collapse;">
<tr>
    <th scope="col">Column1</th><th scope="col">Column2</th><th scope="col">IsMatch</th>
</tr><tr>
    <td>1</td><td>1</td><td>
            </td>
</tr><tr>
    <td>2</td><td>2</td><td>
            </td>
</tr><tr>
    <td>3</td><td>4</td><td>
            </td>
</tr><tr>
    <td>4</td><td>5</td><td>
            </td>
</tr>

JQUERY:

$("#gvCommentSample tr").each(function(){
    if($(this).find("td:eq(0)").html()==$(this).find("td:eq(1)").html())
    {
       //$(this).find("td:eq(2) span").text("matched");
       $(this).find("td:eq(2)").html("<img alt='' src='Image/matchedImage.png' />");
    }   
});

单击此处查看演示

Try this one.Given example may be helpful for you.

HTML:

<table cellspacing="0" rules="all" border="1" id="gvCommentSample" style="width:30%;border-collapse:collapse;">
<tr>
    <th scope="col">Column1</th><th scope="col">Column2</th><th scope="col">IsMatch</th>
</tr><tr>
    <td>1</td><td>1</td><td>
            </td>
</tr><tr>
    <td>2</td><td>2</td><td>
            </td>
</tr><tr>
    <td>3</td><td>4</td><td>
            </td>
</tr><tr>
    <td>4</td><td>5</td><td>
            </td>
</tr>

JQUERY:

$("#gvCommentSample tr").each(function(){
    if($(this).find("td:eq(0)").html()==$(this).find("td:eq(1)").html())
    {
       //$(this).find("td:eq(2) span").text("matched");
       $(this).find("td:eq(2)").html("<img alt='' src='Image/matchedImage.png' />");
    }   
});

CLICK HERE TO SEE THE DEMO

谁的新欢旧爱 2024-11-07 13:11:29
let opdatalist = document.getElementsByClassName("opdata")
    for (let i = 1; i <= opdatalist.length; i++) {
        if (document.getElementById("predata" + i).textContent != document.getElementById("postdata" + i).textContent) {
            let newopdata = document.getElementById("postdata" + i)
            newopdata.style.fontWeight = "bold";
            newopdata.style.backgroundColor = "yellow";
        }
    }    
<table class="datatable-master mt-2" border="1">
    <tr>
        <th>Measurement</th>
        <th>Engineering A&S</th>
        <th>Approved A&S</th>
    </tr>
    <tr class="opdata">
        <td>Varus/Valgus Angle
            (Measured from the Femoral Anatomic Axis to the Tibial
            Mechanical Axis)</td>
        <td id="predata1">3.6° Valgus</td>
        <td id="postdata1">3.6°</td>
    </tr>
    <tr class="opdata">
        <td>Flexion/Extension Angle
            (Measured from the Femoral Anatomic Axis to Tibial
            Mechanical Axis on the Sagittal Plane)</td>
        <td id="predata2">2.3° Flexion</td>
        <td id="postdata2">2.3° Flexion</td>
    </tr>
    <tr class="opdata">
        <td>Hip-Ankle Line</td>
        <td id="predata3">761.3 mm</td>
        <td id="postdata3">761.3 mm</td>
    </tr>
    <tr class="opdata">
        <td>HKA Angle</td>
        <td id="predata4">X°</td>
        <td id="postdata4">7°</td>
    </tr>
    <tr class="opdata">
        <td>Distal cut is referenced to </td>
        <td id="predata5">Mechanical Axis – 0° Valgus</td>
        <td id="postdata5">Mechanical Axis – 0° Valgus</td>
    </tr>
    <tr class="opdata">
        <td>Femoral rotation</td>
        <td id="predata6">3° external to posterior
            condyles</td>
        <td id="postdata6">4° external to posterior
            condyles</td>
    </tr>
    <tr class="opdata">
        <td>Distal resection level</td>
        <td id="predata7">10 mm</td>
        <td id="postdata7">10 mm</td>
    </tr>
    <tr class="opdata">
        <td>Femoral component flexion/extension</td>
        <td id="predata8">X°</td>
        <td id="postdata8">X°</td>
    </tr>
    <tr class="opdata">
        <td>Size/Technology</td>
        <td id="predata9">4R Evolution® CS</td>
        <td id="postdata9">4R Evolution® CS</td>
    </tr>
    <tr class="opdata">
        <td>Distal Medial Resection</td>
        <td id="predata10">10 mm</td>
        <td id="postdata10">12 mm</td>
    </tr>
    <tr class="opdata">
        <td>Distal Lateral Resection</td>
        <td id="predata11">8.6 mm</td>
        <td id="postdata11">8.6 mm</td>
    </tr>
</table>

let opdatalist = document.getElementsByClassName("opdata")
    for (let i = 1; i <= opdatalist.length; i++) {
        if (document.getElementById("predata" + i).textContent != document.getElementById("postdata" + i).textContent) {
            let newopdata = document.getElementById("postdata" + i)
            newopdata.style.fontWeight = "bold";
            newopdata.style.backgroundColor = "yellow";
        }
    }    
<table class="datatable-master mt-2" border="1">
    <tr>
        <th>Measurement</th>
        <th>Engineering A&S</th>
        <th>Approved A&S</th>
    </tr>
    <tr class="opdata">
        <td>Varus/Valgus Angle
            (Measured from the Femoral Anatomic Axis to the Tibial
            Mechanical Axis)</td>
        <td id="predata1">3.6° Valgus</td>
        <td id="postdata1">3.6°</td>
    </tr>
    <tr class="opdata">
        <td>Flexion/Extension Angle
            (Measured from the Femoral Anatomic Axis to Tibial
            Mechanical Axis on the Sagittal Plane)</td>
        <td id="predata2">2.3° Flexion</td>
        <td id="postdata2">2.3° Flexion</td>
    </tr>
    <tr class="opdata">
        <td>Hip-Ankle Line</td>
        <td id="predata3">761.3 mm</td>
        <td id="postdata3">761.3 mm</td>
    </tr>
    <tr class="opdata">
        <td>HKA Angle</td>
        <td id="predata4">X°</td>
        <td id="postdata4">7°</td>
    </tr>
    <tr class="opdata">
        <td>Distal cut is referenced to </td>
        <td id="predata5">Mechanical Axis – 0° Valgus</td>
        <td id="postdata5">Mechanical Axis – 0° Valgus</td>
    </tr>
    <tr class="opdata">
        <td>Femoral rotation</td>
        <td id="predata6">3° external to posterior
            condyles</td>
        <td id="postdata6">4° external to posterior
            condyles</td>
    </tr>
    <tr class="opdata">
        <td>Distal resection level</td>
        <td id="predata7">10 mm</td>
        <td id="postdata7">10 mm</td>
    </tr>
    <tr class="opdata">
        <td>Femoral component flexion/extension</td>
        <td id="predata8">X°</td>
        <td id="postdata8">X°</td>
    </tr>
    <tr class="opdata">
        <td>Size/Technology</td>
        <td id="predata9">4R Evolution® CS</td>
        <td id="postdata9">4R Evolution® CS</td>
    </tr>
    <tr class="opdata">
        <td>Distal Medial Resection</td>
        <td id="predata10">10 mm</td>
        <td id="postdata10">12 mm</td>
    </tr>
    <tr class="opdata">
        <td>Distal Lateral Resection</td>
        <td id="predata11">8.6 mm</td>
        <td id="postdata11">8.6 mm</td>
    </tr>
</table>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文