how to remove "#" from pressed link and alert the value of href?
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:
I want to remove "#" sign.
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....
精彩评论