Open link with jquery
I'm totally not good at jQuery, but this is getting hilarious. Searching the web for 2 hours, trying to found how t开发者_运维知识库o open a link with jQuery, without any result.
I have tried this example: http://jqueryui.com/demos/button/#default
What I want is from the example above, change this code (and get it to work):
<a href="#">An anchor</a>
to
<a href="my_site.php">An anchor</a>
How can I do this?
$("a[href='#']").attr('href', 'my_site.php');
$('a').attr('href', 'my_site.php');
however I advise you to give you link an id so it does not do this to ALL links, so
<a id="linkness" href="#" >An anchor</a>
$('#linkness').attr('href', 'my_site.php');
That page adds an event handler to the buttons' click events. That event handler returns false
which is a technique for telling the browser "don't actually follow this link when someone clicks it." This prevents the link from behaving the way you expect.
This should work:
$('a[href=#]').attr('href', 'my_site.php');
If you have more than one anchor tag on your page, you'll probably want a better selector than a[href=#]
, but you get the idea.
Here's a working example: http://jsfiddle.net/FishBasketGordo/WGPYp/
精彩评论