2015-01-21 5 views
0

내에서 elementId로부터 얻을 방법은 몇 가지 코드가 있습니다.다른 함수

내가하려는 것은 이미지 맵을 클릭하여 요소의 ID를 얻는 것입니다. 내가이 fuction를 사용하는 경우

<area id="cupandplates" alt="" title="cupandplates" href="javascript:new_training()" shape="rect" coords="212,127,295,196" style="outline:none;" target="_self"  /> 
<area id="3cups" alt="" title="3cups" href="javascript:new_training()" shape="rect" coords="313,147,415,201" style="outline:none;" target="_self"  /> 
<area id="beerstines" alt="" title="beerstines" href="javascript:new_training()" shape="rect" coords="200,231,269,290" style="outline:none;" target="_self"  /> 

:

function reply_click(clicked_id) 
{ 
alert(clicked_id); 
} 

을 변경 내 지역의

<area id="cupandplates" alt="" title="cupandplates" href="javascript:new_training()" onClick="reply_click(this.id)" shape="rect" coords="212,127,295,196" style="outline:none;" target="_self"  /> 
<area id="3cups" alt="" title="3cups" href="javascript:new_training()" onClick="reply_click(this.id)" shape="rect" coords="313,147,415,201" style="outline:none;" target="_self"  /> 
<area id="beerstines" alt="" title="beerstines" href="javascript:new_training()" onClick="reply_click(this.id)" shape="rect" coords="200,231,269,290" style="outline:none;" target="_self"  /> 

내가 뭘 이제 얻을 것은 그것은 적절한 ID

을 알려드립니다 :

이것은 항목 1입니다. 항목 삭제

이 cupandplates이 항목 삭제 1 : 1

이이 아이템 3 그렇게 내가 얻을 수 있도록 변경하는 것을 3

임 확실하지 않은 항목 삭제입니다 항목이 삭제 항목 2

입니다

이 3cups이이 항목 3

삭제 beerstines은 2

항목을 삭제하다

도움이 될 것입니다. 호출 할 때

+0

당신은 new_training'href = "javascript : new_training (this.id)"에서 param으로 id를 전달하고 싶지 않고'new_training (id) {document.getElementById (id) .style = ""; // etc ..}' –

답변

0

당신은 거의 자신의 문제를 해결했습니다. 당신이 제목을 찾고있는 것 같습니다

는 ID가 전체

<area id="cupandplates" alt="" title="cupandplates" href="javascript:new_training()" onClick="reply_click(this)" shape="rect" coords="212,127,295,196" style="outline:none;" target="_self"  /> 
<area id="3cups" alt="" title="3cups" href="javascript:new_training()" onClick="reply_click(this)" shape="rect" coords="313,147,415,201" style="outline:none;" target="_self"  /> 
<area id="beerstines" alt="" title="beerstines" href="javascript:new_training()" onClick="reply_click(this)" shape="rect" coords="200,231,269,290" style="outline:none;" target="_self"  /> 

으로 이벤트 트리거 개체를 전달하고

function reply_click(element) 
{ 
    alert(element.getAttribute("title")); 
} 
를 사용하여 제목을 액세스 전달하는 대신 영역 요소 속성 값을
+0

어떻게 return_click (element) 함수를 new_training() 함수에 전달하고 변수로 사용할 수 있습니까? –

+0

reply_click()에서 new_training()을 호출하고 var를 추가 할 때 href = "javascript : new_training()" – Hemant

+0

을 삭제하십시오. delLink = 'This is item'+ tr + ' Delete Item ' + tr + ' '; 어떻게해야합니까?이 항목은 '+ tr +'의 "tr"부분을 설정합니까? –

0

당신은 요소에 심판을 통과해야합니다 직접 ID를 전달하려면

function new_training(el) 
{ 
    var id = el.getAttribute("id"); 
    //use the id 
} 

OR :

<area id="cupandplates" alt="" title="cupandplates" href="javascript:new_training(this)" shape="rect" coords="212,127,295,196" style="outline:none;" target="_self"  /> 
<area id="3cups" alt="" title="3cups" href="javascript:new_training(this)" shape="rect" coords="313,147,415,201" style="outline:none;" target="_self"  /> 
<area id="beerstines" alt="" title="beerstines" href="javascript:new_training(this)" shape="rect" coords="200,231,269,290" style="outline:none;" target="_self"  /> 

그런 다음 자바 스크립트 함수 내에서, 같은 심판을 사용 다음과 같이하십시오 :

<area id="cupandplates" alt="" title="cupandplates" href="javascript:new_training(this.id)" shape="rect" coords="212,127,295,196" style="outline:none;" target="_self"  /> 

희망이

,536을하는 데 도움이
+0

이 메서드를 사용할 때 "undefined"가 나타납니다 –