jQuery - use variable as function name

前端 未结 2 715
一生所求
一生所求 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:45

    To invoke the function passed in as a string, you could do

    function disablePlugin(functionName) {
        $('#divID')[functionName]('disable')
    }
    
    disablePlugin('sortable');
    
    0 讨论(0)
  • 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']

    0 讨论(0)
提交回复
热议问题