2012-03-28 3 views
1

나는 그 (것)들과 일치하는 엄지 손톱을 가진 연결의 소장품이있다. 배경 이미지가 설정된 div로 이러한 미리보기 이미지를로드해야합니다. 모든 축소판 그림이있는 단일 이미지를 사용하므로 이미지를 이미지로로드 할 수 없습니다. 그러나 링크를 클릭하는 것과 동일한 작업을 수행해야 이미지를 클릭하면, 내가 무슨 뜻인지 보여주기 위해 (문제를 보여주기 위해)을 JSFiddle을했다 :앵커 링크에서 클릭 트리거

the JSFiddle

내가 거기 새 창에서이 링크를 클릭하면 내가 원하는 사이트가 열립니다. 그러나 미리보기 이미지를 클릭하면 트리거 된 링크를 클릭 할 수 없습니다.

링크를 클릭하면 추가 기능 (통계)이 생기므로 같은 맞춤 함수를 앵커와 div에 바인딩하는 것보다 링크를 클릭하는 것이 더 좋습니다. 사전에

덕분에

답변

5

안녕 데모 여기에 사용 :http://jsfiddle.net/f6FJ3/19/

를 트리거 이유로이 읽기 : jQuery: trigger click() doesn't work?

코드 아래 It's important to clarify that doing jQuery('#open').click() does not execute the href attribute of an anchor tag so you will not be redirected. It executes the onclick event for #open which is not defined.

점점 창의 원하는 출력을 얻을 것이다 이미지를 클릭하면 열립니다.

JQuery와 코드

$(document).ready(function(){ 
    $('.tmb').click(function(){ 
     var target=$(this).parent().find("a"); 

     $("#debug").text("clicked "+target.text()); 
     //target.triggerHandler('click'); 
     window.open(target.attr('href')); 

    }); 
});​ 

희망이, 환호를하는 데 도움이!

7

HTML4에서 click 이벤트는 입력 요소와 일부 브라우저, 특히 FF, strictly followed the specification에 대해서만 정의되었습니다. 그러나 HTML5 게임은 변화하고 현대적인 브라우저 ,이 기능을 구현하지만 jQuery를 여전히 (jquery trigger method에서 발췌)이 이벤트에 대한 특별한 경우를 가지고 : 당신이에서 코드를 변경 할 수있는 해결 방법으로

if (!onlyHandlers && !event.isDefaultPrevented()) { 

    if ((!special._default || special._default.apply(elem.ownerDocument, data) === false) && !(type === "click" && jQuery.nodeName(elem, "a")) && jQuery.acceptData(elem)) { 

    // Call a native DOM method on the target with the same name name as the event. 

:

target.trigger("click"); 

target.get(0).click(); 
관련 문제