📜  检查 href javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:49.742000             🧑  作者: Mango

代码示例1
// CHECK HREF
const navLinks = document.querySelector(".nav_link");
const navLink = navLinks.getAttribute("href");
const browserHref = window.location.href; // browserHref.search(navLink)

function sliceLink() {
   if (browserHref.includes(navLink)) {
     let searchLink = browserHref.search(navLink); // get position
     let slicedString = browserHref.slice(searchLink); // result
     return slicedString;
   }
}