【问题标题】:This mouseover() to access href and src links only results in "ERR_FILE_NOT_FOUND"? Would like to access href and src via mouseover()这个 mouseover() 访问 href 和 src 链接只会导致“ERR_FILE_NOT_FOUND”?想通过 mouseover() 访问 href 和 src
【发布时间】:2021-08-17 05:15:51
【问题描述】:

我想创建一个鼠标悬停函数来访问 href 和 src 链接。然而我得到的只是错误,“ERR_FILE_NOT_FOUND”你的文件无法访问。它可能已被移动、编辑或删除。”。

HTML 代码:

    
     <p><a href=https://readcomiconline.li/Comic/Punisher-Soviet/Issue-2?id=164726#18>OhGod.</p> 
     <p><a href=http://www.nononsenseselfdefense.com/shop/index.php?l=product_detail&p=45>Oh man</a></p>`

 </body>



<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

jquery 代码:

$("a").mouseover(function(){
  location.assign($("a"));
   });
});

如何通过鼠标悬停访问 href 和 src 链接,就像我点击了它们一样?谢谢。

【问题讨论】:

    标签: html jquery href mouseover onmouseover


    【解决方案1】:

    首先,您需要使用&lt;/a&gt; 关闭您的第一个锚标记

    现在,要获取 href 值,只需将其放在鼠标悬停函数中:

    $(this).getAttribute("href");
    

    您可以将它分配给一个变量( myLink = $(this).getAttribute("href"); )或对它做任何你想做的事情。

    【讨论】:

      猜你喜欢
      • 2022-11-03
      • 2016-08-22
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 2011-03-24
      • 2013-10-16
      • 2014-09-04
      • 2021-12-30
      相关资源
      最近更新 更多