How to insert javascript variables into a URL

后端 未结 3 1753
终归单人心
终归单人心 2020-12-31 11:45
var a = 1;
var b = 2;
var mylink = \"http://website.com/page.aspx?list=\' + a + \'&sublist=\' + b + \'\";

This doesn\'t work. Is there a simple

3条回答
  •  星月不相逢
    2020-12-31 11:53

    var a = 1;
    var b = 2;
    var mylink = `http://website.com/page.aspx?list=${a}&sublist=${b}`;
    

    Copied from above answer.

    Do notice that it is not single quote.

提交回复
热议问题