我正在使用来自Twitter的bootsrap,这很酷。但是,我有一个小问题。我正在尝试使用Popover插件即时生成与类.colorInput的每个输入相关的颜色选择器

这是我想出的代码:

$('.colorInput').each(function()
{
    var src = $(this);

    src.popover({
        html:   true,
        trigger:    'manual',
        content:    function(){
            return $('<div/>').farbtastic(src);
        }
    }).focus(function(e){

        src.data('data-default', src.val());

        $('.colorInput').each(function(){
            $(this).popover('hide');
        });
        src.popover('show');


    }).blur(function(e){
        if(src.data('data-default') != src.val())
        {
            formSubmit();
        }

        src.popover('hide');
    });
});


除一个巨大的细节外,其他所有功能都运行良好:当我通过以下方式设置弹出式窗口的内容时

return $('<div/>').farbtastic(src);


返回的数据将被farbtastic插件附加的任何eventHandlers带区分开。
知道如何使代码保持尽可能简单,并且不丢失附加到返回的任何事件吗?

谢谢 !

最佳答案

我不熟悉这些插件/库,但我建议以下内容:

更改

 content:    function(){
    return $('<div/>').farbtastic(src);
 }




 content:    function(){
    return $('<div id="placeholder" />');
 }


并在调用farbtastic之前附加show

.focus(function(e){

    src.data('data-default', src.val());

    $('.colorInput').each(function(){
        $(this).popover('hide');
    });

    $('<div id="placeholder" />').farbtastic(src);
    src.popover('show');
}

关于jquery - 具有Bootstrap颜色选择器内容的Twitter Bootstrap Popover.js丢失附加事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8140394/

10-12 00:05
查看更多