不同的函数以前一页的链接ID为条件

时间:2013-12-31 10:38:27

标签: javascript jquery

我有3个元素指向同一个URL,但每当加载该URL时,必须根据打开它的元素的id执行不同的函数。

这可以用Javascript / jQuery吗?

1 个答案:

答案 0 :(得分:0)

我认为您可以将哈希用于您的目的。我不太清楚你的要求,但可能对你有所帮助

<a href="www.abc.com#test1" />
<a href="www.abc.com#test2" />
<a href="www.abc.com#test3" />

现在您在abc.com中加载页面后。在页面加载事件中,您可以执行

if(location.hash == "#test1")
// do test1 work
else if(location.hash == "#test2")
// do test2 work
else if(location.hash == "#test3")
// do test3 work