[英]How to alert hashtag after clicking an anchor
我想提醒#
上产生了一个锚的点击标签#
标签。 但我只在页面刷新后收到警报:
锚:
$folderanchor = "<a class='folderanchor' href='#".$dir.'/'.$file."'>$file</a>";
echo $folderanchor;
阅读#
:
$( document ).ready(function() {
if(window.location.hash) {
var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
alert (hash);
// hash found
} else {
// No hash found
}
});
单击锚点后应立即显示警报。 我究竟做错了什么?
单击锚链接不一定会重新加载页面。 您可能想为此使用一个事件。
$('a[href^="#"]').click(yourFunction);
这会在所有锚链接上设置一个点击事件。
将您拥有的代码(没有文档准备好的部分)放入函数 (yourFunction) 中。
添加 +
href='# + ".$dir.'/'.$file."'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.