2011-05-09 145 views
-1

我有一個JQ插件,我需要調用外部插件的嵌套函數。我該怎麼稱呼它?下面是例子功能的插件中:調用jquery插件的內部函數

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); 
} 
+4

不要這麼懶 - 寫 – 2011-05-09 13:32:18

+1

你是不是這就很清楚你有什麼具體的問題的問題。如果您嘗試調用該函數會發生什麼?代碼如何看起來不起作用?你有錯誤嗎? – sth 2011-05-09 13:44:11

回答

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'));