我有一些这样的代码,
<form id="abc"> <input type="text" id="txt" /> </form>现在我想像这样重定向,
and now I want to redirect like this,
var temp = $("#txt").val(); url = "example/" + temp; window.location.replace(url); // or window.location(url);无论如何在jQuery中可以解决这个问题吗?它仍然让我拥有 url = example.
Is there anyway in jQuery to solve this? It still lets me have url = example.
推荐答案正如其他答案中提到的,您不需要 jQuery 来执行此操作;您可以只使用标准属性.
As mentioned in the other answers, you don't need jQuery to do this; you can just use the standard properties.
但是,您似乎不知道 window.location.replace(url) 和 window.location = url 之间的区别.
However, it seems you don't seem to know the difference between window.location.replace(url) and window.location = url.
当然,两者都有其用例,但在我看来,在这种情况下,您应该坚持使用后者.
Of course, both have their use cases, but it seems to me like in this case you should stick with the latter.
P.S.:您可能忘记了 JavaScript 第 2 行 http: 后面的两个斜杠:
P.S.: You probably forgot two slashes after http: on line 2 of your JavaScript:
url = "abc/" + temp;更多推荐
使用 jQuery 更改 URL 和重定向
发布评论