对话关闭第二次不起作用?

时间:2017-03-08 06:30:37

标签: javascript jquery dialog

我想这样:如果用户点击了收藏夹按钮我会显示对话框

“报告添加到收藏夹”

用户在第二次创建对话框时单击了收藏夹按钮

“报告已从收藏中移除”

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

我的代码如下:

             $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");但它唯一的工作是第一次。我猜理由同样的身份?

请问这是怎么回事?

1 个答案:

答案 0 :(得分: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(){
	var status  = $(this).attr('status');
	if(status ==1){
		$(this).attr('status',0);
		alert('Report added to favorites');
	}else{
		$(this).attr('status',1);
		alert('Report removed from favorites');
	}
})
         </script>