问题描述
我想创建一个鼠标悬停函数来访问 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 链接,就像我点击它们一样?谢谢。
解决方法
首先,您需要使用 </a>
现在,要获取 href 值,只需将其放入鼠标悬停函数中即可:
$(this).getAttribute("href");
您可以将它分配给一个变量( myLink = $(this).getAttribute("href"); )或使用它做任何您想做的事情。