I have a svg map and I am putting that into object and I am trying to create all path with id clickable.(我有一个svg映射,并将其放入对象,并尝试创建ID为clickable的所有路径。)
For that I am doing this to get svg object :(为此,我这样做是为了获取svg对象:)
let a = document.getElementById("biharsvg")
And I am putting that into svg doc like this:(我将其放入svg doc中,如下所示:)
var svgDoc = a.contentDocument;
And now I am getting all the values of certain class using this:(现在,我使用以下命令获取某个类的所有值:)
let de = svgDoc.getElementsByClassName("fil0");
I can also get the attribute id value using this:(我还可以使用以下方法获取属性ID值:)
var i;
for (i = 0; i < de.length; i++) {
var j = de[i].getAttribute("id");
console.log(j);
}
I want to add a click event on each attribute id and get the value when I am doing this:(我想在每个属性ID上添加一个click事件,并在执行此操作时获取该值:)
var i;
for (i = 0; i < de.length; i++) {
var j = de[i].getAttribute("id");
console.log(j);
svgDoc.getElementById(j).onclick = function() {
modal.style.display = "block";
console.log(this.getAttribute("id"));
}
}
This is working fine and I am getting all the values but in jquery I can use this:(这工作正常,我正在获取所有值,但是在jquery中,我可以使用以下代码:)
$(de).click(function(){
alert(this.getAttribute("id"));
});
Is there any way I can use something like this in javascript without loop.(有什么办法可以在无循环的javascript中使用类似的方法。) My question is what is the best possible way to make this work in javascript.(我的问题是用javascript进行这项工作的最佳方法是什么。)
ask by translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…