我试图动态地改变颜色。
reponse = JSON.parse(reponse);
$('area').each(function() {
$(this).attr('data-maphilight', '{"stroke":0, "fillColor":"CCFFCC", "fillOpacity":0.3, "alwaysOn":true}');
// POUR LA CRÉATION DE BD, METS TOUS LES TERRAIN DANS COMMENTAIRES AVEC UN TYPE 1
// $('#commentaireArea').val( ($('#commentaireArea').val().concat("('"+$(this).attr('id')+"', 1), \n")));
})
for (var i = 0; reponse.length > i; i++) {
var test = '#'.concat(reponse[i].nomTerrain);
$(test).attr('data-maphilight', '{"stroke":0, "fillColor":"FF0000", "fillOpacity":0.3, "alwaysOn":true}');
}
$('img[usemap]').maphilight();这个只能工作一次。说到第二次,就不会了!它改变CSS类,但不改变后期!
发布于 2015-06-12 03:02:16
这样做的方法是使用.data()而不是.attr()
reponse = JSON.parse(reponse);
$('area').each(function() {
$(this).data('maphilight', {"stroke":0, "alwaysOn": true, "fillColor":"CCFFCC", "fillOpacity":0.3})
// POUR LA CRÉATION DE BD, METS TOUS LES TERRAIN DANS COMMENTAIRES AVEC UN TYPE 1
// $('#commentaireArea').val( ($('#commentaireArea').val().concat("('"+$(this).attr('id')+"', 1), \n")));
})
for (var i = 0; reponse.length > i; i++) {
var id = '#'.concat(reponse[i].nomTerrain);
$(id).data('maphilight', {"stroke":0, "alwaysOn": true, "fillColor":"FF0000", "fillOpacity":0.3})
}效果很好。
https://stackoverflow.com/questions/30788867
复制相似问题