【问题标题】:Show div with jquery colorbox using a button使用按钮显示带有 jquery colorbox 的 div
【发布时间】:2012-11-30 20:46:25
【问题描述】:

我有一个 jquery 函数,它决定向用户显示哪条消息,其中之一是 3 条消息。我在页面上各自的隐藏 div 中有这三条消息。

当用户单击页面上的按钮时,该函数被调用,根据结果,我想使用颜色框在弹出窗口中显示 3 个 div(#msg1、#msg2 或 #msg3)之一。

但是,Colorbox 文档显示使用带有 HREF 的链接来确定要显示的 div;我想使用我的功能。所以我尝试了这个,但它弹出我们的颜色框但不是我的 div,它是空的:

 $(function() {
        $('#calcbtn').bind('click', function(){
            var score = 0;
            $('.rb:checked').each(function(){
                score+=parseInt($(this).val(),10);
            });
            // here i have logic to choose the div, assume #msg1 is the div
            $(this).colorbox({inline:true, href:"#msg1", width: "50%", height: "50%"});
        });
    });

【问题讨论】:

    标签: jquery colorbox


    【解决方案1】:

    我想我可能拥有它:

     $(function() {
            $('#calcbtn').bind('click', function(){
                var score = 0;
                $('.rb:checked').each(function(){
                    score+=parseInt($(this).val(),10);
                });
                //$("input[name=sum]").val(score)
                //alert('score is '+score);
                var $msg;
                if (score > 25) {
                    $msg = $('#msg1');
                } else if (score < 15) {
                    $msg = $('#msg3');
                } else {
                    $msg = $('#msg2');
                }
                $.colorbox({inline:true, href:$msg, width: "50%", height: "50%"});
            });
        });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-13
      • 2016-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多