Apply jQuery UI widgets to ajax loaded elements

后端 未结 3 920
感动是毒
感动是毒 2020-12-18 01:21

I want to activate the jQueryUI button widget on a given selector, lets say \'.button\'.

Whats the best way to automatically activate the widget on any new \'.button

3条回答
  •  青春惊慌失措
    2020-12-18 02:07

    Since all jquery commands have a uniform structure it is really easy to use any object (including json data from a ajax request) as a jquery command

    Sample:

    var jc = {
        'selector': '#sample',
        'method': 'dialog',
        'options': {'title': 'I am a sample'}
    }
    
    $(jc.selector)[jc.method](jc.options);
    

    is the same as

    $('#sample').dialog({'title': "I am a sample}};

    http://jsfiddle.net/wb5Ee/

提交回复
热议问题