버튼이 들어있는 옥 템플릿에서 동적으로 생성 된 객체가 있습니다. 그 안에있는 버튼을 클릭하면 객체를 가져올 수 있어야합니다. 저는 여기에 현재동적 버튼 jQuery가 포함 된 객체 가져 오기
mixin ad(name,media,payout)
.box.box-primary
.box-header.with-border
h3.box-title=name
.box-body
img(src=media, style='width:130px;height:100px;')
p.text-muted.text-center="$"+payout
p.text-muted.text-center preview
.box-footer.text-right
button.btn.btn-primary(type='button',id="share",name="share",onclick='getSelf()') Share
나는 그냥 "정의되지 않은"인쇄하지만 어떻게 내가 이름을 인쇄 때문에 내 jQuery를이 잘못 알고있는 jQuery를
var getSelf = function() {
var clickedBtnID = $(this).parent();
alert('you clicked on button #' + clickedBtnID.name);
}
이 무엇인가?
감사합니다.
패스 '온 클릭 함수 파라미터로서 elem'. –
@Agalo의 솔루션을 사용하여 "this"참조를 캡처/전달하는 대신 이벤트 대상을 캡처하는 것이 더 좋습니다. –