我想在加載后自動編輯某些網站中的兩個特定行。我想編輯<div >到 <div style="display:none">和<div style="display:none">。<div >在網站上編輯的部分是相同的,但我不能說在哪一行,所以需要搜索。沒關系,如果這發生在頁面加載之前或之后。例如,我查看了 Tampermonkey 和 Stylus。還是有更好的解決方案?
uj5u.com熱心網友回復:
使用這個片段。
// Gets all elements with className 1 given in quotes and takes the first element of that list by using [0]
const divOne = document.getElementsByClassName("1")[0];
changeDisplayOnElement(divOne);
//Similarly
const divTwo = document.getElementsByClassName("2")[0];
changeDisplayOnElement(divTwo);
//change the property display under style to none, if it's block
function changeDisplayOnElement(element){
element.style.display = element.style.display === "none" ? "block" : "none";
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/436784.html
下一篇:無法將兩個div水平居中
