【发布时间】:2021-10-18 04:25:17
【问题描述】:
所以到目前为止我一直面临的问题是我目前正在尝试使用 javascript,以便根据一些变量设置我的 area 标签的 coords 属性(它是什么并不重要)。但是,坐标需要 4 个输入 (x1,y1,x2,y2),并且我有一些我不会使用该变量的值。这意味着我必须在输入中混合字符串和变量,而我不知道该怎么做。
为了让您更好地了解我在做什么,这里是一个摘要:
var p = some random value
var q = some random value
var a1 = document.getElementById(areaID);
a1.setAttribute("coords", "0,0, p,q")
当然这不起作用,因为 "" 使它认为 p,q 是字符串而不是变量。所以我尝试了其他方法都失败了(一些绝望的尝试)。
a1.setAttribute("coords", 0,0,p,q);
a1.setAttribute("coords", "0,0," + p + "," + q);
document.getElementById(areaID).coords = 0,0, p,q;
const list = ["0","0", p,q];
a1.setAttribute("coords", list);
那么有谁知道我怎么可能做到这一点?
【问题讨论】:
标签: javascript html area coords