2

我需要删除一个 div,但它没有我可以用来选择它的标识符(类、id)。

这是div:

<div style="background-image: url(&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6RDhCQzBDREZCQ0ZGMTFFMEIxQkFCQ0MxOEQzMzc5NTEiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6RDhCQzBDRTBCQ0ZGMTFFMEIxQkFCQ0MxOEQzMzc5NTEiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDpEOEJDMENEREJDRkYxMUUwQjFCQUJDQzE4RDMzNzk1MSIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDpEOEJDMENERUJDRkYxMUUwQjFCQUJDQzE4RDMzNzk1MSIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PoOauxEAAAALSURBVAgdYzA+AwABNQEAGVbmvQAAAABJRU5ErkJggg%3D%3D&quot;); z-index: 99998; position: absolute; top: 0px; left: 0px; width: 100%; height: 5809px;"></div>

有没有办法用 Greasemonkey 选择这个 div?

4

1 回答 1

3
  • div 相对于一些更可选的元素可能具有固定的代码位置。

  • 如果 div 没有唯一的 CSS 路径,它可能有唯一的 XPath。(除非您声明在这种情况下它的顺序并不总是相同。)

  • 如果背景图像始终相同,您可以通过它来选择它。例如:

    var badDiv  = document.querySelector (
        "div[style*='iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC']"
    );
    badDiv.parentNode.removeChild (badDiv);
    

    或者使用 jQuery:

    $("div[style*='iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC']"). remove ();
    
  • 或者,选择属性的position: absolute; top: 0px;一部分。style

  • 最后,div 可能具有您可以使用的独特内容。(此问题中未显示。)

于 2013-09-21T05:28:39.700 回答