jQuery Modal and FancySelect Plugin

jQuery Modal and FancySelect Plugin

本文关键字:Plugin FancySelect and Modal jQuery      更新时间:2023-09-26

我安装了jQuery FancySelect插件。工作良好。现在我试图在模式弹出窗口中调用它,但它不起作用。这是父窗口中的代码:

<script src="/js/fancySelect.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
    $('.fancyselect').fancySelect();
    var repoName    = 'fancyselect'
    var menu        = $('#top').find('menu');
    function positionMenuArrow() {
        var current = menu.find('.current');
        menu.find('.arrow').css('left', current.offset().left + (current.outerWidth() / 2));
    }
    $(window).on('resize', positionMenuArrow);
    menu.on('click', 'a', function(e) {
        var el          = $(this),
        href            = el.attr('href'),
        currentSection  = $('#main').find('.current');
        e.preventDefault();
        menu.find('.current').removeClass('current');
        el.addClass('current');
        positionMenuArrow();
        if (currentSection.length) {
            currentSection.fadeOut(300).promise().done(function() {
                $(href).addClass('current').fadeIn(300);
            });
        }
        else {
            $(href).addClass('current').fadeIn(300);
        }
    });
    menu.find('a:first').trigger('click')
});
</script>

class="fancyselect"添加到父项中的任何选择中。但是,如果添加到modal popup select,则不起作用。

这里只是推测,因为您没有显示处理弹出窗口创建的HTMLJS逻辑。当你调用:时,你想从弹出插件中应用FancySelect方法的元素已经在页面上了吗

$('.fancyselect').fancySelect();

如果元素是在页面加载后添加的,则该语句不会拾取这些元素。当显示弹出窗口时,你会做一些类似的事情

$('#popupcontainer .fancyselect').fancySelect();

因此,他们将所有所需的代码也将应用于这些元素。

更新:

在你的原始帖子中给出更新后,你可以添加类似的内容:[未测试]

onLoad: function() { 
    var wrap = this.getOverlay().find(".contentWrap"); 
    $(wrap).find('.fancyselect').fancySelect();         
}    

这应该在弹出窗口填充后触发。