【发布时间】:2026-02-06 13:00:01
【问题描述】:
如何在javascript中以90°的度数显示风向(包括在数字后使用小圆圈度数符号)?
我只能在文字描述中显示 - 代码如下。
谢谢。
function text(d) {
let directions = ['Northerly', 'North Easterly', 'Easterly', 'South Easterly', 'Southerly', 'South Westerly', 'Westerly', 'North Westerly'];
d += 22.5;
if (d < 0)
d = 360 - Math.abs(d) % 360;
else
d = d % 360;
let w = parseInt(d / 45);
return `${directions[w]}`;
}
【问题讨论】:
-
您能否提供更多信息,例如
d的值,您在此处传递text(d) { ... }以及HTML 代码.. -
d 的值是度数。链接 - jsfiddle.net/yqoxcLfb/3
标签: javascript jquery weather weather-api