2017-12-12 6 views
-3

링크에 추가하고 싶습니다.자바 스크립트 html 태그 요소에 onclick 추가

$("#email").find("a").onclick = function() { 
     javascript:window.location= 'mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location; 
    } 

그러나이 작동하지 않습니다

onclick="javascript:window.location='mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location;" 

는 그래서 내가 좋아하는 뭔가를 시도

<a id="email" href="#" onclick="javascript:window.location='mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location;">Email</a> 

제공합니다.

+0

'$는 ("# 메일은") ("A"를) 찾을 수) ((기능을 클릭 {같이 location.href = '흔한 : 대상 = 흥미로운 정보 및 몸이 = 난 당신이있을 거라고 생각합니다 이 정보는 흥미 롭습니다 : '+ window.location';});'다음과 같은 것 .. ['click'] (https://api.jquery.com/click/) 핸들러를 읽으십시오. –

+0

* "jQuery click"*에 대한 간단한 웹 검색은 올바르게 수행하는 방법에 대한 많은 결과를 나타냅니다. – charlietfl

+0

@GGo의 게시물에 대한 질문에 답변이 있으면 그 답의 녹색 체크를 클릭하여 답을 표시하십시오. 이 두 가지 모두 당신에게 몇 가지 포인트를 수여하고 자신의 대답이 귀하의 질문과 일치했다는 것을 다른 사람에게 알리도록하십시오 :-) – Wndrr

답변

1

onclick 이벤트는 사용되지 않습니다. 대신을 시도해보십시오..

$("a#email").click(function() { 
    window.location.href = 'mailto:?subject=Interesting information&body=I thought you might find this information interesting: ' + window.location.href; 
} 
+1

감사합니다. 이 하나의 일 :) – LovePoke