2016-04-25 39 views
1

我想使用Sweet Alert獲取Angularjs中的單選按鈕值。有沒有辦法獲得選定的單選按鈕值。我正在使用SweetAlert v1.1.3 anf ngSweetAlert指令。如何使用AngularJS獲取SweetAlert中的單選按鈕值

SweetAlert.swal({ 
    title: "Please Select:", 
    text: '<form> <div class=""> <input type="radio" name="csvSelect" id="radio1" ng-model="radioValue" ng-value="1" > <label for="radio1"> Whole records </label> </div> <div class=""> <input type="radio" name="csvSelect" id="radio2" ng-model="radioValue" ng-value="2" ng-click="getVal()"> <label for="radio2"> Selected records </label> </div></form>', 
    html: true, 
    showCancelButton: true, 
    confirmButtonText: "Download it!", 
    cancelButtonText: "Cancel", 
    closeOnConfirm: false, 
    closeOnCancel: true, 
    showLoaderOnConfirm: true 
}, 
function (isConfirm) { 
    if (isConfirm) { 
     SweetAlert.swal("Deleted!", $scope.radioValue, "success"); 
    } 
}); 

回答

3

在這裏你去 - http://jsbin.com/lonotipeba/edit?js,output

我覺得sweetAlert適用display:none輸入元素。所以對於大單選按鈕感到抱歉,你可以用你的CSS控制。當你點擊下載按鈕時,你會看到JS警報中收音機的價值。

您可以通過SweetAlert的function完成您的目標。

P.S點擊使用JS按鈕查看sweetAlert。

+0

有沒有什麼方法可以不使用jQuery語句'$(...)' –

+0

你可以使用vanilla JS。只有一行在jquery中,你可以很容易地更改爲JS。 –

相關問題