简体   繁体   English

当使用jQuery在行位于顶部或底部时如何更改图标颜色

[英]How to change Icon colour when row is at top or bottom using jquery

I've built my table through string html format in vb.net and getting data through databases into the table in form of rows and columns. 我已经在vb.net中通过字符串html格式构建了表,并通过数据库以行和列的形式将数据获取到表中。

Rows are moving Up and Down using jquery onclick function , 使用jquery onclick function ,行在Up and Down移动,

All I want is when a row is at top then the blue arrow become gray because It is not allowed to move above and same is for bottom. 我想要的只是一行位于顶部,然后蓝色箭头变为灰色,因为不允许其向上移动,底部也是如此。

I can show you my table in this picture: 我可以在这张照片中显示我的桌子: 在此处输入图片说明

Here is jquery onclick function: 这是jquery onclick函数:

$(document).on('click', '.HashirDown', function () {


var parentRow = $(this).closest('tr');

parentRow.insertAfter(parentRow.next());

});

$(document).on('click', '.HashirUp', function () {

    var temp = $(".HashirUp").index(this);
    if ($(".HashirUp").index(this) > 0) {

    var parentRow = $(this).closest('tr');

    parentRow.insertBefore(parentRow.prev());
}
else {
    return false;
}
});

Here is the StringHtml Format table : 这是StringHtml格式表:

 For i = 0 To DT.Rows.Count - 1
        StrHtml = String.Format("{0}<tr>", StrHtml)
        StrHtml = String.Format("{0}<td   colspan=""2"">{1}</td>", StrHtml, DT.Rows(i).Item("Decsription"))
        StrHtml = String.Format("{0}<td   colspan=""2"">{1}</td>", StrHtml, DT.Rows(i).Item("Condition"))
        StrHtml = String.Format("{0}<td  >{1}</td>", StrHtml, DT.Rows(i).Item("Result_"))
        StrHtml = String.Format("{0}<td  >{1}</td>", StrHtml, DT.Rows(i).Item("Type_"))
        StrHtml = String.Format("{0}<td >{1}</td>", StrHtml, DT.Rows(i).Item("PS_ID_Redirect"))
        StrHtml = String.Format("{0}<td >{1}</td>", StrHtml, DT.Rows(i).Item("TPL_Discount"))
        StrHtml = String.Format("{0}<td  >{1}</td>", StrHtml, DT.Rows(i).Item("Hub_Redirect"))

        If i = 0 Then
            StrHtml = String.Format("{0}<td class=""HashirUp""><img class=""btn_img"" src=""../icon/up.png""  title=""Can not move up, already first""/></td>", StrHtml, DT.Rows(i).Item("Order_"))
        Else
            StrHtml = String.Format("{0}<td class=""HashirUp""><img class=""btn_img "" src=""../icon/up.png""   title=""Move up the order""/></td>", StrHtml, DT.Rows(i).Item("Order_"))
        End If
        If i = DT.Rows.Count - 1 Then
            StrHtml = String.Format("{0}<td class=""HashirDown""><img class=""btn_img"" src=""../icon/down.png""  title=""Can not move down, already last""/></td>", StrHtml, DT.Rows(i).Item("Order_"))
        Else
            StrHtml = String.Format("{0}<td class=""HashirDown""><img class=""btn_img "" src=""../icon/down.png""   title=""Move down the order""/></td>", StrHtml, DT.Rows(i).Item("Order_"))
        End If

        StrHtml = String.Format("{0}<td class=""edit up""><a href=""#"" onclick=""Get_Price_Key_IU('{1}');"">Edit</a></td>", StrHtml, DT.Rows(i).Item("PS_ID"))
        StrHtml = String.Format("{0}<td class=""delete up""><a href=""#"" onclick=""Del_Price_Key('{1}');"">Delete</a></td>", StrHtml, DT.Rows(i).Item("PS_ID"))
        StrHtml = String.Format("{0}</tr>", StrHtml)

    Next
    StrHtml = String.Format("{0}</table>", StrHtml)
    Return StrHtml

You can use css filter property 您可以使用CSS 过滤器属性

 .gray { -webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */ filter: grayscale(100%); } 
 <img src="https://www.gravatar.com/avatar/c7757f497ba7c0bbe832d91989e935eb?s=32&amp;d=identicon&amp;r=PG&amp;f=1" alt="" width="32" height="32"> <br><br> <img class="gray" src="https://www.gravatar.com/avatar/c7757f497ba7c0bbe832d91989e935eb?s=32&amp;d=identicon&amp;r=PG&amp;f=1" alt="" width="32" height="32"> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM