【问题标题】:How to open a colorbox with specific Id or class?如何打开具有特定 ID 或类的颜色框?
【发布时间】:2013-09-23 05:52:49
【问题描述】:

我有以下代码:

<div class="hidden">
  <div id="deletePopContent" class="c-popup">
    <h2 class="c-popup-header">Delete Practice Sheet</h2>
    <div class="c-content">         
      <h3>Are you sure to delete this practice sheet?</h3>
      <p class="alert"><strong>You are about to perform an action which can't be undone</strong></p>
      <a href="#"class="c-btn">No</a><a href="#"class="c-btn" id="delete_url">Delete</a> 
    </div>
  </div>
</div>

$(document).ready(function(){ 
$(document).on('click', '.edit_user_transaction_status', function (e) { 

    e.preventDefault();

      $.colorbox.close();

     //for confirmation that status change
    var ans=confirm("Are you sure to change status?");
    if(!ans) {
        return false;
    }

    var post_url           = $(this).attr('value');
    var transaction_status_update = $('#transaction_status_update').val();     

    $.ajax({
      type: "POST",
      url: post_url+"&transaction_status_update="+transaction_status_update,
      data:$('#transaction_form').serialize(),
      dataType: 'json',  
      success: function(data) {           
        var error = data.login_error;

        $(".ui-widget-content").dialog("close");
        //This variables use for display title and success massage of transaction update          
      var dialog_title   = data.title;              
      var dialog_message = data.success_massage; 
      //This get link where want to rerdirect
      var redirect_link  = data.href;       
      alert(redirect_link);
      /*var $dialog = $("<div class='ui-state-success'></div>")
                    .html("<p class='ui-state-error-success'>"+dialog_message+"</p>")
                    .dialog({
                  autoOpen: false,
                  modal:true,
                  title: dialog_title,
                  width: 500,
                  height: 80,
        close:  function(){                   
        document.location.href =redirect_link;

        }        
        });*/         
          /*$dialog.dialog('open');*/ 
          document.location.href =redirect_link;
          $.colorbox({inline:true, width:666});

         }          
      });
   });
});

【问题讨论】:

    标签: javascript ajax json jquery colorbox


    【解决方案1】:

    你需要使用href属性,比如:

    $.colorbox({
       inline:true, 
       href: "#deletePopContent",
       width:666
    });
    

    你正在重定向:

    document.location.href =redirect_link; <-- remove this
    $.colorbox({inline:true, width:666, href: "#deletePopContent"});
    

    所以只需删除它,它应该可以工作

    您可以使用onClosed colorbox 事件,以便在关闭 colorbpx 弹出窗口后重定向:

    $.colorbox({
        inline:true, 
        href: "#deletePopContent",
        width:666,
        onClosed: function() {
           window.location.href = redirect_link;
        }
    });
    

    【讨论】:

    • :你的把戏确实对我有用。但是现在新的问题已经产生了。弹出窗口会在一秒钟内自动关闭。您能否为我提供此问题的解决方案,以便在用户单击关闭按钮之前出现颜色框弹出窗口?
    • @JSLover 查看我添加的答案.. 希望对您有所帮助
    • :非常感谢,你的这个技巧也对我有用。但是现在还有一个小问题。我应该如何打开变量redirect_link 中包含的URL。更新完成后,我想将 URL 重定向到变量中的页面。颜色框弹出窗口实际上仅用于显示成功消息。
    • @JSLover 查看我添加的答案
    猜你喜欢
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多