小编Bri*_*son的帖子

加载动态"选择"选择元素

我正在使用所选的jQuery插件(由Harvest).它在(document).ready上运行正常,但我有一个按钮,当单击它时,使用ajax动态创建更多选择对象,我想使用"选择"功能.但是,只有原始选择元素具有"选定"功能,而新(动态创建)功能不起作用.我正在使用jQuery.get来追加新元素.以下是代码示例:

jQuery(".select").chosen();//this one loads correctly
jQuery("#add-stage").click(function() {
    jQuery.get('/myurl',{},function(response) {
            //response contains html with 2 more select elements with 'select' class
            jQuery('#stages').append(response);
        jQuery(".select").chosen();//this one doesn't seem to do anything :-(
    });
});
Run Code Online (Sandbox Code Playgroud)

我在想某个地方需要一个.live()函数,但我还没有想到它.任何帮助深表感谢!

注意 - 我没有尝试动态加载新选项,如使用文档中所指定的那样 trigger("liszt:updated");

ajax jquery jquery-plugins

8
推荐指数
2
解决办法
3万
查看次数

标签 统计

ajax ×1

jquery ×1

jquery-plugins ×1