2017-03-08 87 views
0

我想:如果用户点击收藏夹按钮我告诉对话框第二次关闭对话框不起作用?

“报告添加到收藏夹”

和用户点击我创建对话框

“报告从收藏夹删除收藏夹按钮第二次“

再次,但对话框具有相同的ID。

我的代码为S以下:

   $scope.toogleReportToFavorites = function (item) { 
       if (!item.isInFavorites) { 
        item.isInFavorites = true; 
        RepService.AddToDefaultFavourites(item.ReportId, function (reportCat) { 
         if ($scope.showRemovedDialog) { 
          $("#denemePicker").dialog("close"); //its works only first time 
          $scope.showAddedDialog = false; 
         } 
         else { 
          $scope.showAddedDialog = true; 
         } 
         WarningDialogs("Report added to favorites"); 
        }, function (ex) { 
         GlobalErrorHandler(ex); 
        }); 
       } else { 
        item.isInFavorites = false; 
        RepService.RemoveFromFavourites(item.ReportId, function() { 
         if ($scope.showAddedDialog) { 
          $("#denemePicker").dialog("close"); 
          $scope.showRemovedDialog = false; 
         } 
         else { 
          $scope.showRemovedDialog = true; 
         } 
         WarningDialogs("Report removed from favorites");  
        }, function (ex) { 
         GlobalErrorHandler(ex); 
        }); 
       } 
      }; 

,这是我WarningDialogs功能代码:

function WarningDialogs(text, messageType, dialogWidth, callback, textAlign) { 
    if (textAlign == null || textAlign.length < 1) { 
     textAlign = 'center'; 
    } 
    $('<div>', { title: "deneme", id: 'denemePicker' }).html(text).css('text-align', textAlign).dialog(
      { 
       resizable: true, modal: true, closeOnEscape: true, width: dialogWidth, 
       create: function() { 
        isWarningDialogsShown = true; 
        $(this).css('maxHeight', '300px'); 
       }, 
       close: function (event, ui) { 
        isWarningDialogsShown = false; 
        if (callback) { 
         callback(); 
        } 
       }, 
       buttons: { 
        Close: function() { 
         $(this).dialog("close"); 
        } 
       } 
      }).css('overflow', 'auto'); 
    return; 
} 

我要永远为这方面的工作:$("#denemePicker").dialog("close");,但其只工作第一次。我猜想原因相同的ID?

请问我该怎么办?

回答

0

此代码可以帮助你

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
<button type="button" class="btn btn-info" style="width:90%;" id="textChanger" status="1" onclick="counter;">D Box</button> 
 
<script> 
 
$(document).on('click','#textChanger',function(){ 
 
\t var status = $(this).attr('status'); 
 
\t if(status ==1){ 
 
\t \t $(this).attr('status',0); 
 
\t \t alert('Report added to favorites'); 
 
\t }else{ 
 
\t \t $(this).attr('status',1); 
 
\t \t alert('Report removed from favorites'); 
 
\t } 
 
}) 
 
     </script>