나는 약간의 시간 전에 썼던 간단한 (가벼운) div 슬라이더를 사용했고, 여러 다른 프로젝트에서 사용하기 때문에 - 자신의 플러그인으로 래핑하는 시간이왔다. 더 이상!).커스텀 JQuery 플러그인 - 사용자 정의 옵션을 얻거나 유지하는 방법?
내 플러그인 체리가 터지기 때문에 나는 읽고, 복사 중이고 http://docs.jquery.com/Plugins/Authoring에서 읽었습니다. (대부분)하지만 뭔가 이상한 점이 있습니다. 여기 내 플러그인 코드입니다 : 여기
(function($) {
//List of callable methods
var methods = {
init : function(options) {
var settings = $.extend({
optionOne : 'aaa',
optionTwo : 'bbb',
optionThree : 'ccc',
optionFour : 'ddd'
}, options);
},
error : function(message) {
alert(message);
},
showSettings : function() {
//This bit... how to show whats in 'settings' defined in init?
}
}
$.fn.ccSlider = function(method) {
//Calling methods
if (methods[method]) {
//If plugin is called with a recognised method, run that.
return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
//if plugin is called without a method, run the init() function
return methods.init.apply(this, arguments);
} else {
//Run the error() function to catch all else.
return methods.error("ccSlider: Method '"+method+"' does not exist!");
}
};
})(jQuery);
모든 것이 예상대로 작동하지만, 내가 필요로하는 방법을 쓰기에 갈 수 없어,하지만 난 알아낼 수 없습니다 때문 설정 '의 콘텐츠에 액세스하는 방법 'init() 메소드 외부.
테스트로 'showSettings'를 사용하고 있는데 ... 어떻게 나타 났으며 지정한 설정 (예 : optionTwo)의 값이 무엇인지 알려주는 showSettings 메서드를 작성하는 방법은 무엇입니까?
.. 아니면 JQuery 웹 사이트에 따르면 ... – Codecraft