【发布时间】:2012-03-21 11:10:10
【问题描述】:
我正在使用 JQuery maphilight 插件来突出显示世界地图中的区域。现在我已经为区域元素设置了以下默认选项
fillColor: 'F25607' //orange color
alwaysOn: 'true'
因此在页面加载时,区域元素会以橙色着色。我对每个区域元素都有一个 onclick 事件。 我需要将地图中单击区域元素的突出显示颜色(即填充颜色)更改为不同的颜色,如绿色 当我单击地图中的另一个元素时,该元素应变为绿色,而前一个选定的元素应变回橙色。 这是我的地图的示例代码
<img id="theImg" class="map" src="/gra/images/worldblank.png" usemap="#worldmap" />
<map id="worldmap" name="worldmap">
<area class='area' shape="circle" alt="Israel" title="Israel" coords="423,232,7" href="#" onclick="loadActivity('Israel');" />
<area class='area' shape="circle" alt="China" title="China" coords="548,229,5" href="#" onclick="loadActivity('China');" />
</map>
要完成的示例 js 函数将是:
<script>
jQuery(document).ready(function(){
jQuery('.map').maphilight();
});
$(function() {
$('.area').click(function(e) {
e.preventDefault(); // from the samples, i guess used to overrride default options
// get the clicked area element and set its fillColor to green
// make the previous selected area fillColor to the default options value (if we need to do this)
// use the trigger function to trigger this change
});
});
</script>
【问题讨论】: