访问jQuery控件之外的方法

时间:2012-03-27 07:18:51

标签: javascript jquery

我有一个JQuery控件,它有一些私有方法。我想在控件之外访问这些方法。一些代码片段可以让您更加了解。

这两个方法在同一个java脚本文件中。

function addSiblings(currentbtn) {

    var dvClick = $(currentbtn).closest('div').siblings('div.OrgGroupLists')
    var spnElement = $(dvClick).find('span.bgLime');
    objEditParam.renderRadio = false;
    var dvPrnt =  createDivNode(objEditParam);
    //Want to access "createDivNode" method.
   }

(function ($) {

function createDivNode(objEditParam) {
        var countSpan;
        var dvPrnt = document.createElement("div");
        countSpan = OS_hdnCount;
        dvPrnt.id = "dv_Pr_" + countSpan;
}

})(jQuery);

我如何调用该方法。

1 个答案:

答案 0 :(得分:0)

(function ($) {

    //use an event handler instead
    $('element_selector').on('click',function(){

        //call the function and passing it the target
        addSiblings(this);
    })

    function addSiblings(currentbtn) {
        var dvClick = $(currentbtn).closest('div').siblings('div.OrgGroupLists')
        var spnElement = $(dvClick).find('span.bgLime');
        objEditParam.renderRadio = false;
        var dvPrnt =  createDivNode(objEditParam);

        //you can now access createDivNode()
    }

    function createDivNode(objEditParam) {
        var countSpan;
        var dvPrnt = document.createElement("div");
        countSpan = OS_hdnCount;
        dvPrnt.id = "dv_Pr_" + countSpan;
    }

})(jQuery);