87,910
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title> test </title>
</head>
<body>
<a name="test1" /><a name="test2" /><a name="test3" /><a name="test4" />
<div id="info" style="width:300px;height:50px;border:1px solid #ddd;">the infomation field</div>
<a class="func" href="#test1">test1</a><br />
<a class="func" href="#test2">test2</a><br />
<a class="func" href="#test3">test3</a><br />
<a class="func" href="#test4">test4</a><br />
<script type="text/javascript">
function getArgs (url)
{
var _url = "";
if (url)
{
_url = url;
}
else
{
var _url = window.location.href;
}
if (_url.split("#").length <= 1)
{
return "";
}
else
{
return _url.split("#")[1].split(".");
}
}
function reload (url)
{
document.getElementById("info").innerHTML = getArgs(url);
}
</script>
</body>
</html>
window.onload=function()
{
var links = document.getElementsByTagName("a");
for (var i=0; i<links.length; i++)
{
if (/(^|\s)func($|\s)/.test(links[i].className))
{
links[i].onclick = function (){reload(this.href)};
}
}
}
var oldLocation = location.href;
setInterval(function() {
if(location.href != oldLocation) {
do your action
oldLocation = location.href;
}
}, 1000);
document.onclick=function(){}
window.onload=window.onbeforeunload=function() { var links = document.getElementsByTagName("a"); for (var i=0; i<links.length; i++) { if (/(^|\s)func($|\s)/.test(links[i].className)) { links[i].onclick = function (){reload(this.href)}; } } }
这样不行?