简体   繁体   English

字体真棒图标js文件问题

[英]Font awesome icon js file issue

So i have a font awesome icon with an id of facebook,i put that in a variable in JavaScript with getelementbyid method in main.js file in index.html when i clicked on the the icon, it is opening without any issue.所以我有一个字体真棒图标,id 为 facebook,我把它放在 JavaScript 的一个变量中,在 index.ZFC35FDC70D5FC69D269883A822EC7A 上打开图标时没有任何问题。
but on other pages in the website it is not opening when the id and the code is same.the main.js is loaded at the end.the icon has same id on each page and i am calling it with the same js file, but i am failed to understnad how is it opening on the index.html but not on other pages.但是在网站的其他页面上,当 id 和代码相同时,它不会打开。最后加载 main.js。每个页面上的图标都有相同的 id,我用相同的 js 文件调用它,但是我无法理解它是如何在 index.html 上打开的,但在其他页面上却没有。

------------------------------------------------------------------------

HTML CODE HTML 代码

 <footer>
          <p>All Rights Reserved</p>
          <div id="footicons">
               <i class="fab fa-facebook fa-1x"></i>
               <i class="fab fa-instagram-square fa-1x"></i>
               <i class="fab fa-twitter fa-1x"></i>
          </div>
     </footer>

     <script src="/js/main.js"></script>
</body>

</html>

---------------------------------------------------------

Javascript code Javascript代码

let facebook = document.querySelector(".fa-facebook");

function openfblink() {
  window.location = "https://www.facebook.com";
}

facebook.addEventListener("click", openfblink);

Can you make sure you are pointing to the right place for the JS file?你能确定你指向了 JS 文件的正确位置吗? If the other files you are trying to access the JS from is in another folder than index.js, the path will be different.如果您尝试从中访问 JS 的其他文件位于 index.js 之外的另一个文件夹中,则路径将不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM