简体   繁体   中英

Use jQuery to navigate away from page

I will only have a relative link available to me but I want to use jQuery to navigate to this rel link. I only see AJAX functionality in jQuery. How can I do this using jQuery or just pure HTML/JavaScript?

window.location.href = "/somewhere/else";

你不需要jQuery,简单的window.location代码会这样做,例如:

window.location.href = myUrl;

Other answers rightly point out that there is no need to use jQuery in order to navigate to another URL; that's why there's no jQuery function which does so!

If you're asking how to click a link via jQuery then assuming you have markup which looks like:

<a id="my-link" href="/relative/path.html">Click Me!</a>

You could click() it by executing:

$('#my-link').click();
window.location = myUrl;

无论如何,这不是jQuery:它是简单的javascript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM