我正在使用flowchart.js创建图表。我希望能够将单击事件绑定到图中的每个箭头,以便对该唯一路径执行某些操作。
据我所知,这些线路没有身份证...有没有办法绕过这个问题?
发布于 2018-01-26 16:15:37
我验证了您所写的内容,您是正确的,行(svg路径)没有I。而且,看起来他们没有太多的编程API。因此,我想出了一种为每个路径分配ID的老套方法。
在调用diagram.drawSVG(...);之后,添加以下代码,为每个路径创建惟一的ID。
var i = 0;
$("path").each(function() {
$(this).attr("id", "path" + i.toString());
i++;
});然后,我向path元素添加了一个click处理程序,以验证ID是否被正确分配。
$(document).on("click", "path", function () {
//Display to the console
var clickedPath = $(this)[0];
console.log(clickedPath);
// Build a string of attributes by looping them
var alertString="";
for (i=0; i < clickedPath.attributes.length; i++) {
alertString += clickedPath.attributes[i].name + "=" + clickedPath.attributes[i].value + "\n";
}
//Alert the attributes
alert(alertString);
});https://stackoverflow.com/questions/48456248
复制相似问题