[英]Issues with my jQuery plugin
我已經為手風琴創建了一個基本插件。 我的代碼在我的手風琴.js文件中,該文件在包含jQuery庫之后立即包含在內。 使用Accordion.js文件中的此代碼的手風琴沒有問題。
(function($) {
$.fn.accordion = function(options) {
var settings = $.extend({
speed:300,
}, options);
return this.each(function() {
var $elm = $(this),
s = settings.speed;
$elm.on('click',function(e) {
$('.accordion-toggle').on('click', function(e){
$elm.each(function() {
if(!$(e.target).is(this)) {
$($elm.attr('data-target')).slideUp(s);
$(this).removeClass('active');
}
});
});
$($elm.attr('data-target')).slideToggle(s);
$elm.toggleClass('active');
e.stopPropagation();
});
});
}}(jQuery)); $(".accordion-toggle").accordion();
但是,當我從頁面上使用速度選項啟動此操作時,它會發生兩次。
$(".accordion-toggle").accordion({ speed: 500, });
問題出在哪兒?
在手風琴.js文件中,您有$(".accordion-toggle").accordion();
您可以刪除它並嘗試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.