在我后面的代码中,我使用常量 String 和 String.Format 来创建一系列 svg 元素,如下所示:
const string BoxTemplate = "<rect x=\"{0}\" y=\"{1}\" height=\"{2}\" width=\"{3}\" fill=\"{4}\" stroke=\"#707070\" onmouseover=\"showToolTip()\"/>";
string s = String.Format(BoxTemplate, x, y, h, w, color);
然后我使用文字控件来渲染图像。
我想在元素中包含数据或至少一个数据键,以供鼠标悬停或使用其他事件。我考虑过将 id 设置为 datakey,但在某些情况下,不止一个图像会引用相同的数据。
什么是让我的 javascript 函数识别“鼠标悬停”的元素并访问其数据/数据键的最佳方法。