1
기본 대화 상자를 쓰려고합니다. 나는 클릭 할 때 대화 상자를 시작할 링크 요소를 지정할 수 있기를 원합니다.사용자 지정 이벤트 트리거 및 바인딩?
I'n 데이터를 사용하여이 동작을 지정하는 대화 상자 HTML 속성 :
<a id="launch-dialog" href="#"></a>
<div class="dialog" data-behavior="dialog" data-trigger="#launch-dialog">
<!-- dialog html -->
</div>
$(function(){
$("[data-behavior='dialog']").dialog();
});
실제 jQuery를 확장 그래도 난에 문제가있어 일부입니다. 'dopen'
이벤트가 본문에서 올바르게 트리거되지 않았거나 이벤트 바인딩이 올바르게 설정되지 않았습니다. data-trigger
의 클릭 이벤트는 확실히 발사되고 있습니다. 내가 "열린 감지 된"로그를 보지 못하는 이유는 무엇입니까?
(function($) {
var methods = {
init: function(options) {
if (this.data('trigger')) {
// Add an event listener which causes the dialog to
// open when the correct link is clicked.
$(this.data('trigger')).on('click', function(e) {
e.preventDefault();
// Trigger a global dialog open event which the dialog can subscribe to.
$('body').trigger('dopen');
});
}
},
// Various other methods not shown.
};
$.fn.dialog = function(method) {
// Method handling code not shown...
// Add handlers for custom events triggered on the body element.
$('body').bind('dopen', function(e) {
// This never happns:
console.log("Open detected");
});
};
})(jQuery);