用javascript更改所有的href

Change all a hrefs with javascript?

本文关键字:href javascript      更新时间:2023-09-26

如何在页面加载时使用自定义URL更改所有href?

对不起,我只是不知道我该怎么做。真的不知道任何js。

感谢任何能帮助我的人。真的很感激。

您可以使用这个:

// Execute this when the document is ready.
window.onload = function () {
  // Get all the `<a>` tags.
  var all_a = document.querySelectorAll("a");
  // Loop through all the `<a>` tags.
  for (i = 0; i < all_a.length; i++)
    // Change the `href`:
    all_a[i].setAttribute("href", "whatever_you_want");
}