EnR*_*Lam 5 html javascript jquery svg
我试图让我的 SVG 看起来像一个“饼形”,这看起来都很好,此外,我希望它们每个都有不同的点击事件。
function one() {
alert("1");
}
function two() {
alert("2");
}
function three() {
alert("3");
}
function four() {
alert("4");
}Run Code Online (Sandbox Code Playgroud)
<svg style="position: absolute;height:auto;width:auto;" onClick="one()">
<path d="m 25.857864,25.857865 a 20,20 0 0 1 28.284271,-1e-6 L 40,40 Z"/>
</svg>
<svg style="position: absolute;height:auto;width:auto;" onClick="two()">
<path
d="m 25.857864,-54.142135 a 20,20 0 0 1 28.284271,-10e-7 L 40,-40 Z"
transform="rotate(90)" />
</svg>
<svg style="position: absolute;height:auto;width:auto;" onClick="three()">
<path
d="m -54.142136,-54.142135 a 20,20 0 0 1 28.284271,-10e-7 L -40,-40 Z"
transform="scale(-1)" />
</svg>
<svg style="position: absolute;height:auto;width:auto;" onClick="four()">
<path
d="m 25.857864,25.857865 a 20,20 0 0 1 28.284271,-1e-6 L 40,40 Z"
transform="matrix(0,1,1,0,0,0)"/>
</svg>Run Code Online (Sandbox Code Playgroud)
然而我的问题是,每当我尝试时,代码中的最后一个 SVG 似乎覆盖了代码中的其他 SVG,这样无论圆圈的哪个部分都只会调用最后一个函数 {four() in the example}我点击
一个 svg 标签并将 onClick 函数分配给路径标签,如下所示,它工作正常:
function one() {
alert("1");
}
function two() {
alert("2");
}
function three() {
alert("3");
}
function four() {
alert("4");
}Run Code Online (Sandbox Code Playgroud)
<svg style="position: absolute;height:auto;width:auto;">
<path d="m 25.857864,25.857865 a 20,20 0 0 1 28.284271,-1e-6 L 40,40 Z" onClick="one()"/>
<path
d="m 25.857864,-54.142135 a 20,20 0 0 1 28.284271,-10e-7 L 40,-40 Z"
transform="rotate(90)" onClick="two()"/>
<path
d="m -54.142136,-54.142135 a 20,20 0 0 1 28.284271,-10e-7 L -40,-40 Z"
transform="scale(-1)" onClick="three()" />
<path
d="m 25.857864,25.857865 a 20,20 0 0 1 28.284271,-1e-6 L 40,40 Z"
transform="matrix(0,1,1,0,0,0)" onClick="four()"/>
</svg>Run Code Online (Sandbox Code Playgroud)