【问题标题】:call jquery plugin inner function调用jquery插件内部函数
【发布时间】:2011-05-09 13:30:43
【问题描述】:

我有一个 JQ 插件,我需要在插件外调用嵌套函数。如何调用它?这是插件中的函数示例:

function addTo(from, to)
{
    var dest = jQuery("#"+to)[0];

    jQuery("#"+from+" option:selected").clone().each(function() {
        if (this.disabled == true) return
        jQuery(this)
        .appendTo(dest)
        .attr("selected", false);
}

【问题讨论】:

  • 别这么懒——写个问题
  • 你没有说清楚你有什么确切的问题。如果您尝试调用该函数会发生什么?代码看起来如何不起作用?你有错误吗?

标签: jquery function plugins nested call


【解决方案1】:
function action(elm) {
        if (!elm.disabled) { 
           jQuery(elm).appendTo(dest).attr("selected", false);
        }
}

function addTo(from, to)
{
    var dest = jQuery("#"+to)[0];

    jQuery("#"+from+" option:selected").clone().each(action(this));
}

// OUTSIDE

action(window.getElementById('id'));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    相关资源
    最近更新 更多