Javascript 如何将url中的值复制到html中

Javascript 如何将url中的值复制到html中,javascript,jquery,Javascript,Jquery,我想将url中的值复制到html代码中 i、 e: 当我的url是 www.website.com/page?destination=other_page 我想把报纸上的所有东西都抄下来?对于形式的作用: <form action="/user/register/" method="post" accept-charset="UTF-8"> 应成为: <form action="/user/register/?destination=other_page" method=

我想将url中的值复制到html代码中

i、 e:

当我的url是

www.website.com/page?destination=other_page 
我想把报纸上的所有东西都抄下来?对于形式的作用:

<form action="/user/register/" method="post" accept-charset="UTF-8">
应成为:

<form action="/user/register/?destination=other_page" method="post" accept-charset="UTF-8">

有什么建议吗

您可以使用window.location.search获取整个查询字符串。然后可以使用attr将其附加到当前操作属性,如下所示:

$('form').attr('action', function(i, a) {
  return a + window.location.search;
});

您可以使用Windows获取url。location@slashsharp如果帖子url与当前url不同,则此操作无效page@Brian是的,它可以,窗口中还有很多其他方法。location@slashsharp对,我误解了。location.search要精确,就像下面的答案一样。除了@Rory answer,我建议您进行查找,因为您的代码接缝可能非常容易受到它的攻击。