2016-04-25 37 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。 –

相关问题