1

I want to combine two variables using JavaScript.

var width = window.screen.width;
var height = window.screen.height;

so it would have a var like

var width_height =

How would I combine both of them with one variable and have a output as example below

1600,900
4

2 回答 2

7

像这样连接它们

var1 + "," + var2

演示

更新:正如您更新的问题和评论一样。利用

var width_height  = window.screen.width + "," + window.screen.height; 

更新的演示

于 2013-10-01T20:44:07.810 回答
1

在 Javascript 中,您可以连接字符串

var a = "A";
var b = "B";

以各种方式

使用 +-运算符

var c = a + "," + b;

使用连接

var c = a.concat(",").concat(b);

使用连接

var c = [a,b].join(",");
于 2013-10-01T20:50:44.180 回答