【发布时间】:2015-06-22 18:39:58
【问题描述】:
我有一些 svg 多边形。当您将鼠标悬停在多边形上时,我想找到多边形 id 的一部分,然后更改所有在其 id 中具有该多边形 id 部分的多边形的填充颜色。但它不起作用。没有多边形填充正在改变。请问有人知道我做错了什么吗?
示例多边形:
<polygon id="sandiego0528loss10" fill="#FFFFFF" points="401.821,418.967 392.331,409.824 397.398,404.561 406.871,414.021 "/>
<polygon id="sandiego0528loss9" fill="#FFFFFF" points="391.122,398.292 386.347,403.142 392.317,409.632 397.398,404.561 "/>
jquery
$( "polygon" ).hover(
function() {
if (this.id.length > 0){
var test = this.id.match(/\d{4}/); //see what the date is
if (test !== null ) {
//first part of test will be the date
var thisDate = test[0];
var matchIndex = test["index"];
var thisRow = this.id.substring(0, matchIndex+4);
//get all polygons with this prefix and color them
$('polygon[id^=thisRow]').attr('fill', '#ccc');
}
}
}, function() {
}
);
【问题讨论】: