jQuery - use variable as function name

前端 未结 2 743
一生所求
一生所求 2020-12-30 09:04

In Jquery i\'d like to disable any plugin I want by changing a variable name. However the following code doesnt work

function disablePlugin(functionName) {
          


        
2条回答
  •  一个人的身影
    2020-12-30 09:59

    This is how you would do that:

    function disablePlugin(functionName) {
      $('#divID')[functionName]('disable')
    }
    
    disablePlugin('sortable');
    

    This works because someObject.foo is the same thing as someObject['foo']

提交回复
热议问题