Jquery 将自定义函数设置为";“生活”;最终的结果是

Jquery 将自定义函数设置为";“生活”;最终的结果是,jquery,Jquery,我有一个函数,基本上可以使任何非活动函数成为活动函数 (function($) { $.fn.extend({ collapsiblePanel: function() { // Call the ConfigureCollapsiblePanel function for the selected element return $(this).each(ConfigureCollapsiblePanel);

我有一个函数,基本上可以使任何非活动函数成为活动函数

(function($) {
    $.fn.extend({
        collapsiblePanel: function() {
            // Call the ConfigureCollapsiblePanel function for the selected element
            return $(this).each(ConfigureCollapsiblePanel);
        }
    });

})(jQuery);

function ConfigureCollapsiblePanel() {
    $(this).addClass("ui-widget");

    // Wrap the contents of the container within a new div.
    $(this).children().wrapAll("<div class='collapsibleContainerContent ui-widget-content'></div>");

    // Create a new div as the first item within the container.  Put the title of the panel in here.
    $("<div class='collapsibleContainerTitle ui-widget-header'><div>" + $(this).attr("title") + "</div></div>").prependTo($(this));

    // Assign a call to CollapsibleContainerTitleOnClick for the click event of the new title div.
    $(".collapsibleContainerTitle", this).click(CollapsibleContainerTitleOnClick);
}

function CollapsibleContainerTitleOnClick() {
    // The item clicked is the title div... get this parent (the overall container) and toggle the content within it.
    $(".collapsibleContainerContent", $(this).parent()).slideToggle();
}

     (function ($) {
 $.fn.livecollapsiblePanel = function (opts) {
        this.live("mouseover", function() {
            if (!$(this).data("init")) {
                $(this).data("init", true).collapsiblePanel(opts);
            }
        });
        return $();
    };
}(jQuery));
     $(".collapsibleContainer").livecollapsiblePanel();
(函数($){
$.fn.extend({
可折叠面板:函数(){
//为所选元素调用ConfigureCollapsablePanel函数
返回$(此).each(配置可折叠面板);
}
});
})(jQuery);
函数配置可折叠面板(){
$(this.addClass(“ui小部件”);
//将容器中的内容包装在新的div中。
$(this.children().wrapAll(“”);
//创建一个新的div作为容器中的第一项。将面板的标题放在这里。
$(“”+$(this).attr(“title”)+“”).prependTo($(this));
//为新标题div的click事件分配对collapsbleContainertletionClick的调用。
$(.collapsableContainertitle),this)。单击(collapsableContainertitletonClick);
}
函数collapsibleContainertLeonClick(){
//单击的项目是标题div…获取此父级(整个容器)并切换其中的内容。
$(.collappableContainerContent),$(this.parent()).slideToggle();
}
(函数($){
$.fn.LiveCollapsablePanel=函数(选项){
this.live(“mouseover”,function()){
if(!$(this.data(“init”)){
$(this).data(“init”,true).可折叠面板(opts);
}
});
返回$();
};
}(jQuery));
$(“.collapsablecontainer”).livecollapsablepanel();

我主要做的是在ajax调用中生成可折叠面板,并在div中显示。为了将每个div“激活”为可折叠面板,我当前需要将鼠标悬停在每个div上,然后将其转换为可折叠面板。。。有没有什么方法可以将其更改为当div从ajax调用加载时,它们会变成可折叠的面板

你知道
.live()
不受欢迎,是吗?是的。。但是我使用的是1.7.1,它似乎不起作用……我可以将其更改为委托……但我的主要问题是,我是否可以使用另一个事件来代替鼠标,使这个函数在dom放在页面上时(一旦ajax调用完成)立即作用于dom如果用户不需要与DOM交互,为什么不一起删除
鼠标上方的
事件,然后从
if()
语句开始?我必须启用该live/delgate或…否则它将无法工作。。。