<SCRIPT language="JavaScript">
height = screen.height;
width = screen.width;
document.write(width*height + " pixels");
</SCRIPT>
我想我的答案以逗号分隔数字而不是一个完整数字。尝试以逗号显示JavaScript数字
<SCRIPT language="JavaScript">
height = screen.height;
width = screen.width;
document.write(width*height + " pixels");
</SCRIPT>
我想我的答案以逗号分隔数字而不是一个完整数字。尝试以逗号显示JavaScript数字
这里有一个有趣的方式来做到这一点:
function format(num) {
return ("" + num).split("").reverse().reduce(function(acc, num, i, orig) {
return num + (i && !(i % 3) ? "," : "") + acc;
}, "");
}
format(777782374);
打印:
"777,782,374"
或者,如果你想支持小数:
function format(num, fix) {
var p = num.toFixed(fix).split(".");
return p[0].split("").reduceRight(function(acc, num, i, orig) {
var pos = orig.length - i - 1
return num + (pos && !(pos % 3) ? "," : "") + acc;
}, "") + (p[1] ? "." + p[1] : "");
}
format(777782374, 4);
打印:
"777,782,374.0000"
比你不应该乘以它们?
document.write(width + ", " + height + " pixels");
。这就是为什么需要乘法。 –
他说什么。我试图以整数的形式显示屏幕上的像素总数,但用逗号。例如:1920 x 1080 = 2073600.但我想说它是2,073,600。 – Casualty
也请注意,脚本没有一种“语言”属性 – Jonathan
你的意思是用逗号作为如果宽*高> 1000你有千个分隔符逗号? OP显示的像素总数为 – putvande