1
之前添加HTML我正在使用greasemonkey編輯頁面。我需要在已經在頁面上的兩個表之間添加我自己的表格,然後刪除第二個表格。沒有什麼可以將兩個現有表格分開設置,所以我在insertBefore
的功能上遇到問題。使用greasemonkey在表
<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>
我發現下面的代碼去除表2的幫助,但我需要表2前未添加自己的表:
// find second <table> on this page
var xpathResult = document.evaluate('(//table[@class="details"])[2]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
var node=xpathResult.singleNodeValue;
// now hide it :)
node.style.display='none';
那輝煌。第二種方法使其非常容易。非常感謝! – 2011-01-09 16:21:52