2016-08-12 98 views
0

首先要提到的是,我是Angular JS中的新成員。我已經實現了下面的代碼,我想改變按鈕文本(默認按鈕名稱是「好」和「取消」)。「好吧」按鈕文本爲「是」和「取消」按鈕文本爲「否」模式彈出。有沒有其他的方式來實現這一點?它已在所有瀏覽器中兼容。在Angular Js中更改確認對話框按鈕的文本

$scope.sectionLoad = function (formId, sectionId, parentIndex, index){ 

     if(confirm("Save data?")){ 
       $scope.submit($scope.form, pageId, sectorId); 
     } 
     $scope.search = false; 
     $scope.sectionDataLoad(formId, sectionId, parentIndex); 

    }; 
+0

哪裏模板?你是第三方模態對話框嗎? – Zen

+0

很多關於這個的問題在stackoverflow ...不能標記你的問題,因爲從手機重複...但搜索「HTML確認按鈕標籤」... – Pras

+0

你不能這樣做與本地confirm(),因爲它是瀏覽器的方法。您可以使用自定義模態指令,https://angular-ui.github.io/bootstrap/#/modal – Aks1357

回答

0

總之 - 你不能。在confirm()對話框中沒有確定的方法來改變按鈕。您需要創建一個自定義對話框並使用該對話框代替confirm()

+0

在angular-material.js中提到,我們可以設置自定義消息來確認按鈕:$ mdDialogPreset#ok(字符串) - 設置確認「好」按鈕文本。 * - $ mdDialogPreset#cancel(string) - 設置確認「取消」按鈕文本。 – Duckkiee

+0

這將是您從angular-material.js引用的自定義對話框。 'confirm()'是默認的JavaScript確認對話框。 –

0

由於http://myclabs.github.io/jquery.confirm/

$ scope.loadData =功能(ID,sectionId,parentIndex){

   $.confirm({ 
        title:"Save confirmation", 
        text: "Do you want to save the section data ?", 
        confirm: function (button) { 
         $scope.submit(Id, sectionId, parentIndex, index, 2); 
         $scope.search = false; 
         $scope.sectionLoad(Id, sectionId, parentIndex, index); 
         alert("Section Data Saved."); 
        }, 
        cancel: function (button) { 
         $scope.sectionLoad(formId, sectionId, parentIndex, index); 
         alert("Section data not saved"); 
        }, 
        confirmButton: "Yes", 
        cancelButton: "No" 
       }); 
    }; 
+0

只需要添加jquery.confirm.js和jquery.confirm.min.js :-) – Duckkiee

相關問題