如何更改图片的背景颜色?它包含一个特定的链接
How do I change the background color of the <tr> that contains a certain link?
我想更改一个包含给定链接的"tr"元素的背景色。
我的片段:
var color1 = "red";
var targetForum = $("tr a[href*='showforum=28']");
targetForum.each ( function () {
var thisRow = $(this).parent ().parent ().parent ();
thisRow.style.backgroundColor = color1;
}
我尝试了rgb值以及十六进制,但没有发生任何变化的bg颜色。
目标页面如下所示:
<tr>
<td class="row2" align="center">
<td class="row1" width="3%" align="center">
<td class="row1">
<td class="row1" width="15%">
<span class="forumdesc">
<a title="Off-Topic" href="showforum=41">ForumABC</a>
</span>
</td>
<td class="row1" align="center">
<td class="row2" align="center">
<td class="row1" align="center">223460</td>
<td class="row1">
</tr>
- 看起来你在这里使用jQuery,它是如何加载的(由论坛或GM)
- 当jQuery被论坛加载时,你必须使用
unsafeWindow.$
访问jQuery - parent()返回一个jQuery-Object,你不能使用
obj.style
设置jQuery-Object的style-property,使用css()
代替
我的建议是:(你不需要每一个)
unsafeWindow.$("tr:not(:has(tr)):has(a[href*='showforum=28'])").css('backgroundColor','red');
以jQuery的方式设置样式(如前所述,thisRow
是一个jQuery对象)
那就是:thisRow.css ('backgroundColor', color1);
.
然而,如果网站使用背景图像,颜色可能不会显示生效。用途:
thisRow.css ('background', color1);
,以确保任何BG图像不会掩盖颜色的变化。
最后,站点可以为表格单元格的BG设置样式,这同样可以掩盖行颜色的变化。为了解决这个问题,也可以为<td>
元素设置样式。
也就是:
targetForum.each ( function () {
var thisRow = $(this).parent ().parent ().parent ();
thisRow.css ('background', color1);
thisRow.find ("td").css ('background', color1);
}
相关文章:
- 如何使用JQuery在HTML中创建包含字符串参数的引号的onclickjavascript链接
- 正在尝试将标题标记添加到mailto链接,正文中包含URL
- DataTable如何防止在包含超链接的列中单击行
- JavaScript-更改一组包含特定文本和变量ID元素的链接
- 将.js文件中的数据包含到链接中
- 谷歌表单:在文档的电子邮件中包含超链接'谷歌硬盘的位置
- AngularJS 指令:使用包含/编译链接集合中的对象
- 检查页面标题是否包含在链接属性中,并使用jQuery分配活动类
- WordPress被黑客入侵以包含反向链接
- 根据包含的链接移动DOM中的元素
- 如何在超链接上调用javascript警报's点击,里面有一条包含单引号的消息
- iframe中包含的链接没有任何作用
- 在jquery中,我如何检测一个段落是否包含一个链接,并且只有一个链接而没有其他链接
- 导航到另一个页面,其中包含通过链接的 POST 请求
- 包含推荐链接的HTML iframe
- 在数组中创建包含超链接项的下拉列表
- 使(可能是动态加载的)元素通过JavaScript可点击,但优先考虑其中包含的链接
- 提取包含符号链接的压缩文件
- 如何使用简单的 html 实现 asp.net 的母版详细信息或在标题部分包含标题链接
- 替换/重定向包含锚链接 (#) 的 URL