我有一些像这样的代码,
I have some code like this,
<form id="abc"> <input type="text" id="txt" /> </form>现在我想像这样重定向,
and now I want to redirect like this,
var temp = $("#txt").val(); url = "http:abc/" + temp; window.location.replace(url); or window.location(url);jQuery中有没有解决这个问题?它仍然让我有 url = abc 。
Is there anyway in jQuery to solve this? It still lets me have url = abc.
推荐答案正如其他答案所述,你不需要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.
PS:你可能在 http之后忘了两个斜杠:在JavaScript的第2行:
P.S.: You probably forgot two slashes after http: on line 2 of your JavaScript:
url = "abc/" + temp;更多推荐
使用jQuery更改URL和重定向
发布评论