开发者

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

开发者 https://www.devze.com 2023-04-11 12:40 出处:网络
I have a link <a href=\'#test1\'>some_link开发者_如何转开发</a> When I press it I start some ajax manipulations with it.

I have a link

<a href='#test1'  >some_link开发者_如何转开发</a>

When I press it I start some ajax manipulations with it. Thing is when you press it it adds "#test1" to the address url in browser.

Now:

  1. I want to remove "#" sign.

  2. Alert the value of href also without "#" sign when I press the link.

Is that possible ?


$("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();
    });
});

Example: http://jsfiddle.net/XqKBD/


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

Try that....

0

精彩评论

暂无评论...
验证码 换一张
取 消