javascript通过url传递变量

javascript通过url传递变量,javascript,html,url,variables,Javascript,Html,Url,Variables,嗯,这个问题可能不正确,但我会试一试 我的剧本: <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u);void(o)" onclick="return false">OMG, testing</a> 在这里要添加以下内容:&format=txt 因此,正确的url应该是: http://localhost/url=google.com&format=tx

嗯,这个问题可能不正确,但我会试一试

我的剧本:

<a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u);void(o)" onclick="return false">OMG, testing</a>
在这里要添加以下内容:&format=txt

因此,正确的url应该是:

http://localhost/url=google.com&format=txt
  • 如何将&format添加到在 顶部
    • 像这样:

      <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u + '&format=txt');void(o)" onclick="return false">OMG, testing</a>
      
      
      
      您只需将文本添加到url的字符串中,如下所示:

      <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u + '&format=txt');void(o)" onclick="return false">OMG, testing</a>
      
      
      
      您只需将文本添加到url的字符串中

      这就是您想要的:

      <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format=txt');void(o)" onclick="return false">OMG, testing</a>
      
      
      
      这就是您想要的:

      <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format=txt');void(o)" onclick="return false">OMG, testing</a>
      

      只需使用+,将其添加到链接中,除非我误解了这个问题

      <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>
      
      <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>
      
      
      

      假设txt是一个变量,否则将其全部放在引号中。

      只需使用+,将其添加到链接中,除非我误解了这个问题

      <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>
      
      <a href="javascript:var%20u=location.href;window.open('http://localhost/url='+u+'&format='+txt);void(o)" onclick="return false">OMG, testing</a>
      
      
      

      假设txt是一个变量,否则将其全部放在引号中。

      这样就可以了,您必须像对本地主机一样执行操作


      这样就可以了,您必须像处理本地主机一样进行操作