jQuery按背景颜色查找元素 [英] JQuery Find Elements By Background-Color
本文介绍了jQuery按背景颜色查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试通过使用JQuery查找background-color属性设置为SelectedRowStyle背景色的行来访问GridView的Selected行.该颜色是#FF6600.我已经尝试过
Trying to access the Selected row of a GridView by using JQuery to find the row with the background-color attribute set to the SelectedRowStyle background color. That color is #FF6600. I've tried
var row = $("tr").find().css("background-color", "#FF6600");
但这只是将所有行设置为橙色.
But that just sets all the rows to orange.
var row = $("tr[background-color=#FF6600");
返回空
var row = $("tr").find().attr("background-color");
返回未定义
推荐答案
尝试 .filter
方法.
Try the .filter
method.
var rows = $('tr').filter(function(){
var color = $(this).css("background-color");
return color === "#FF6600" || color === "rgb(255, 102, 0)" ;
});
我还没有测试过,可能需要调整rgb部分以解决间距问题.
I haven't tested it, the rgb part may need to be adjusted to account for spacing.
或更妙的是,这考虑到了大写还是小写
or better yet, this takes into account uppercase vs lowercase
var rows = $('tr').filter(function(){
var color = $(this).css("background-color").toLowerCase();
return color === "#ff6600" || color === "rgb(255, 102, 0)" ;
});
这篇关于jQuery按背景颜色查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文