如何将javascript变量插入URL [英] How to insert javascript variables into a URL

查看:113
本文介绍了如何将javascript变量插入URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

var a = 1;
var b = 2;
var mylink = "http://website.com/page.aspx?list=' + a + '&sublist=' + b + '";

这不起作用。有没有一种简单的方法可以将这些其他变量插入到url查询中?

This doesn't work. Is there a simple way to insert these other variables into the url query?

推荐答案

使用正确的引号:

var a = 1;
var b = 2;
var mylink = "http://website.com/page.aspx?list=" + a + "&sublist=" + b;

如果你用双引号开始一个字符串,它可以用双引号结束并且可以包含单引号,同样的话反过来。

If you start a string with doublequotes, it can be ended with doublequotes and can contain singlequotes, same goes for the other way around.

这篇关于如何将javascript变量插入URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆