javascript 鼠标悬停链接时隐藏href url中的状态栏值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19814076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Hide status bar value from href url when mouse hover a link
提问by Oscar Batlle
This is the link that I have:
这是我拥有的链接:
href='" . $ajax_like_link . "' data-task='like' data-post_id='" . $post_id . "' data-nonce='" . $nonce . "'>";
And I want to replace the displayed link value from status and set to javascript:void(0)
.
我想从 status 替换显示的链接值并设置为javascript:void(0)
.
How can I accomplish this?
我怎样才能做到这一点?
回答by Ilya
Try this:
试试这个:
<a href="javascript:void(0)" onclick="location.href='" . $ajax_like_link . "'">Link</a>
回答by Vicky Gonsalves
you can do it by calling javascript function instead of link in href:
您可以通过调用 javascript 函数而不是 href 中的链接来实现:
<a href='javascript:void(0)' onclick='gotoLink(\"". $ajax_like_link ."\")' .......>link</a>
<script>
function gotoLink(url) {
window.location = url;
}
</script>
回答by Sarath
You can set the status with window.status=''
but most browsers will block attempts to change the status line by default for security reasons
您可以设置状态,window.status=''
但出于安全原因,大多数浏览器默认会阻止更改状态行的尝试
<a href="link" onmouseover="window.status='javascript:void(0)';" onmouseout="window.status='';">link here</a>
So a better way is to
所以更好的方法是
<a href="javascript:void(0)" onclick="location.href='" . $ajax_like_link . "'">Link</a>
回答by Asif Hussain
a more shorter syntax of doing this is
这样做的更短的语法是
<a href="javascript:;" onclick="location.href='" . $ajax_like_link . "'">Link</a>
and there are many other ways of doing this, you can create a jquery function and just put the url in the attibute. e.g
并且还有很多其他方法可以做到这一点,您可以创建一个 jquery 函数并将 url 放在属性中。例如
<a href="javascript:;" rel='" . $ajax_like_link . "'" class="goto">Link</a>
$(".goto").click(function() {
var gotolink = $(this).attr('rel')
if(gotolink!=undefined || gotolink!='')
location.href = gotolink;
});