2013-06-04 24 views
0

我使用以下函數來檢查一定的條件,以便除非條件爲真,顏色框插件不會被解僱!colorbox得到的被解僱的條件是假的jquery

function settleCashInterface(){ 
    var element; 
    $('#bill-list').find(".bill-item-list").each(function(){ 
      if($(this).css("display") == "block"){ 
      element = $(this); 
      return false; 
      }else{ 
       element = 0; 
      } 
     }); 
    if(element != 0){ 
     $(".settle-cash").colorbox({inline:true, width:"72%"}); 
     var data = "billId=" + element.parent().attr("id") + "&settlementType=No"; 
     ajaxCall("/setlement","POST",data,function(response){ 
      $('#settle-cash').find('.table-number').val(response.settleInfo.tableNo); 
      $('#settle-cash').find('.room').val(element.parent().find('.room-number').html()); 
      $('#settle-cash').find('.num-of-guests').val("3"); //hard coded values 
      $('#settle-cash').find('.total').val(response.settleInfo.totalAmout); 
      $('#settle-cash').find('.total-due').val(response.settleInfo.totalAmout); 
      $('#settle-cash').find('.total-due').prop("disabled", true); 
      $('#settle-cash').find('.final-value').html(response.settleInfo.totalAmout); 
      $('#settle-cash').attr("billId",element.parent().attr("id")); 
      $('#settle-cash').attr("billNo",element.parent().find('.bill-number').html()); 
     }); 
     resetAddBill(); 
    }else{ 
     alert("Select a bill"); 
    } 
} 

該函數是click事件和下面的代碼的觸發器!

$('.settle-cash').click(function(){ 
     settleCashInterface(); 
    }); 

如果顯示元素,則應運行顏色框,如果不是,則不應該。當我點擊相應的元素時,如果沒有顯示塊CSS樣式的元素,則會顯示一條消息。我用螢火蟲進行調試。當我第一次點擊條件被完美解僱,彩盒不會顯示!但是當我顯示一個元素並隱藏它時,這個條件就會被觸發並顯示一個警報!當我關閉警告框時,彩盒被解僱!我怎麼能阻止這個!

回答

0

你的代碼看起來不錯。確保你的元素被設置爲塊以外的任何其他元素。所以display: none等,因爲塊是默認值。