我正在尝试使用油脂猴子用我自己的桌子替换桌子。拥有该表的页面有 2 个具有相同类且没有 ID 的表。
我只需要替换第二个表(用我自己的表),并且对第一个表不执行任何操作。没有什么可以真正使第二个表与第一个表不同,所以我唯一能想到的就是尝试在第二个表周围添加一个 DIV,但无法弄清楚。
有任何想法吗?页面代码如下:
<h3>Table 1</h3>
<table class="details" border="1" cellpadding="0" cellspacing="0">
<tbody><tr>
<th>1</th>
<td>2</td>
</tr>
</tbody></table>
<h3>Table 2</h3>
<table class="details" border="1">
<tbody><tr>
<th>1</th>
<td>2</td>
</tr><tr>
<th>3</th>
<td>4</td>
</tr>
</tbody></table>
您可以使用 xpath 查找第二个表,并对其执行某些操作。 xpath 表达式将是(//table[@class="details"])[2]
。下面我添加了一个使用的示例(//pre)[1]
相反,这将找到此页面上的第一个代码块,我将隐藏它作为示例。因此,这隐藏了您问题中的页面代码。(//pre)[2]
将隐藏我的脚本。
也可以看看here http://www.briandonovan.info/articles/public/gm-dom-xpath-01/有关如何使用 xpath 的教程。
// ==UserScript==
// @name so-test
// @namespace test
// @include http://stackoverflow.com/questions/4635696/use-greasemonkey-to-remove-table
// ==/UserScript==
// find first <pre> on this page
var xpathResult = document.evaluate('(//pre)[1]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
var node=xpathResult.singleNodeValue;
// now hide it :)
node.style.display='none';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)