2011-04-05 2 views
0

이미 영역이 강조 표시된 상태에서 다른 조건에 대한 영역 맵 색상을 변경하려면 어떻게해야합니까?다른 조건에 대한 밝은 색상 변경

if(partyname = "Democrat") 
{ 
    var data = $('#MT').data('maphilight') || {fillColor:'ff0000'}; 
    data.alwaysOn = !data.alwaysOn; 
    $('#MT').data('maphilight', data).trigger('alwaysOn.maphilight'); 
} 
if(partyname = "Republican") 
{ 
    var data = $('#MT').data('maphilight') || {fillColor:'000000'}; 
    data.alwaysOn = !data.alwaysOn; 
    $('#MT').data('maphilight', data).trigger('alwaysOn.maphilight'); 
} 

내가지도를 강조하기위한 jquery.maphighlight.min.js jQuery 플러그인을 사용하고 있습니다 :

내 코드입니다.

내 문제는 영역이 첫 번째 버튼으로 붉은 색으로 강조 표시되어 있다는 것입니다. 두 번째 버튼을 클릭하면 같은 영역이 강조 표시되지만 색상을 변경할 수 없습니다 (색상이 검은 색으로 변경되어야 함).

JQuery와 : 같은

+0

다른 하나에서 복사 한 질문입니까? – alex

+1

가능한 [지역이 기본 색상으로 강조 표시된 후 강조 색상 변경] (http://stackoverflow.com/questions/5552302/changing-the-highlight-color-after-thea-are-is-highlighted-with) -default-color) – alex

+4

OMG [방법] (http://stackoverflow.com/questions/5515501/map-highlight-to-change-the-highlight-color-dynamically) [많은] (http://stackoverflow.com/questions/5550875/changing-the-highlight-color-after-the-area-is-highlighted) [사본] (http://stackoverflow.com/questions/5552302/changing-the-highlight-color-after-the -area-is-highlighted-with-default-color) [다시] (http://stackoverflow.com/questions/5552842/changing-the-highlight-color-after-the-area-is-highlighted-with-default -색깔)? 불행히도 오늘 더 많은 표를 얻지 못했습니다. ( – fabrik

답변

0

뭔가

var colorToHighlight = "black" //default 

$("#color_options a").click(function (e) 
{ 
    e.preventDefault(); //stop the anchor tag 

    colorToHighlight = $(this).attr("id"); 
} 

/* 
    Do the highlight stuff 

*/ 

HTML : 당신은 당신이 이전 이름이 올바른 변수를 호출 할 수 있도록

<div id="color_options"> 
    <a href="#" id="green">Green</a> - <a href="#" id="red">Red</a> 
</div> 
+0

jQuery 확장에 익숙하지 않지만 "colorToHighlight"를지도 섹션을 강조 표시하기 위해 색상을 선택하는 데 사용하는 변수로 바꿉니다 – Dormouse

1

우선, colorToHighlight와 "colorToHightlight"를 교체하려고합니다.

0

alt 속성을 사용하여 색상을 유지했습니다.

HTML :

<p><a href="#" class="aToggle" alt="37ee8d">Go GREEN</a></p> 

JS/JQuery와 :

"영역 1"은지도 지역 인
 $('.aToggle').click(function (e) { 
      var data = $('#area1').mouseout().data('maphilight') || {}; 
      data.fillColor = $(this).attr('alt'); 
      $('#area1').data('maphilight', data).trigger('alwaysOn.maphilight'); 
     }); 

.