Javascript jQuery maphilight动态更改颜色
我正在尝试动态更改maphilight的颜色Javascript jQuery maphilight动态更改颜色,javascript,jquery,css,Javascript,Jquery,Css,我正在尝试动态更改maphilight的颜色 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 DAN
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类,但没有改变maphilight 正确的方法是使用.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})
}