如何删除“#"从按下的链接,并提醒href的值

how to remove "#" from pressed link and alert the value of href?

本文关键字:链接 的值 href 删除 何删除 quot      更新时间:2023-09-26

我有一个链接

<a href='#test1'  >some_link</a>

当我按下它时,我会用它开始一些ajax操作。问题是,当你按下它时,它会在浏览器中的地址url中添加"#test1"。

现在:

  1. 我想删除"#"标志。

  2. 当我按下链接时,提醒href的值也不要加"#"号。

这可能吗?

$("a").click(function(){
     var href = $(this).attr('href').substring(1);
     window.history.pushState({state:'new'},'New State', href);
     //do your stuff
     return false;
});
$('a').click(function(e){
    alert($(this).attr('href').replace('#',''));
    e.preventDefault();
});
$(function(){
    $('a').click(function(e){
        alert($(this).attr('href').substring(1));
        e.preventDefault();
    });
});

示例:http://jsfiddle.net/XqKBD/

<a href="javascript:void(0);" onClick="window.location='''" >

试试看。。。。