【发布时间】:2011-11-25 13:50:01
【问题描述】:
编辑:我不是在谈论状态栏显示,我是在谈论您单击以跟随链接的文本。 /编辑
我浏览了一些类似的帖子,但没有找到答案。我有一个想要显示的链接。
www.mylink.com
我希望每次点击链接时链接的href都会改变。
href="www.mylink.com?R=340978"
每次点击后查询字符串都会变为一个随机数,以防止浏览器缓存页面。预计该页面会经常更改并经常查看以评估这些更改。
所以我希望人们看到“www.mylink.com”但指向“www.mylink.com?R=34532”的链接我想我可以通过一个附加新随机数的 onclick 事件来实现这一点并将 href 属性设置为新链接,但这也会更改显示的文本。
<script type="text/javascript">
var baseLink = "http://myDevLink/library/ea26098f-89d1-4305-9f75-afc7937f8336/25/test/036b602b-0bde-e011-957b-1cc1dee8bacd.html";
var link = "";
// Prime the link
$(document).ready(function()
{
NewRandomParam();
});
function NewRandomParam()
{
// Make sure one of the warning messages isn't displayed instead of the link
if (document.getElementById("link") != null)
{
// Add a random number param to the query string to prevent the user from opening a cached version of the page
link = baseLink + "?R=" + Math.floor(Math.random() * 1000000);
document.getElementById("link").setAttribute("href", link);
}
}
</script>
<body>
<div id="divContent" style="display:inline; border:0px" class="tab">
<pre style="margin-top: 0;" >
<font face="tahoma">
<a href="" id="link" onclick=NewRandomParam(); target="_blank">http://myDevLink/library/ea26098f-89d1-4305-9f75-afc7937f8336/25/test/036b602b-0bde-e011-957b-1cc1dee8bacd.html</a>
</font>
</pre>
</div>
</body>
</html>
从上面的代码可以看出,没有关于应该显示什么的查询字符串,但是当我查看页面时,href 的值与查询字符串一起显示。如果我查看源代码,则正确的 url 在那里并且应该显示,但它不是。
请告诉我我在哪里愚蠢。
【问题讨论】:
标签: javascript jquery html href