答案 0 :(得分:0)
编辑:这是自动执行此操作的脚本。
仅当svg路径按此顺序排列时(路径> text> path> text ...)
var svg = document.getElementById("svg")
var count = svg.children.length
var index = []
var reveal = function(a){
var text = index[a]
svg.appendChild(text)
}
var hide = function(a){
var text = index[a]
text.remove()
}
var n = 0
while(n<count-1){
svg.children[n].setAttribute("id", n)
var nn = n+1
svg.children[nn].setAttribute("id", nn)
index.push(svg.children[nn])
n+=2
}
var q = 1
while(q<=count){
document.getElementById(q).remove()
q+=2
}
var nnn = 0
while(nnn<index.length){
svg.children[nnn].setAttribute("onmouseover", "reveal("+nnn+")")
svg.children[nnn].setAttribute("onmouseout", "hide("+nnn+")")
nnn++
}
<svg height="1000" width="1000" id="svg">
<path
d="M 50,50, 75,50 75,75 50,75 z"
fill="yellow">
</path>
<text x="50" y="50" style="fill:gold;">gold</text>
<path
d="M 500,200, 700,200 700,400 500,400 z"
fill="blue">
</path>
<text x="600" y="300" style="fill:black;">Black</text>
<path
d="M 200,200, 400,200 400,400 200,400 z"
fill="red">
</path>
<text x="300" y="300" style="fill:white;">White</text>
<path
d="M 500,200, 700,200 700,400 500,400 z"
fill="blue">
</path>
<text x="600" y="300" style="fill:black;">Black</text>
</svg>