如何使用 AngularJS 在 SweetAlert 中获取单选按钮值

How to get radio button value in SweetAlert with AngularJS

我想使用 Sweet Alert 获取 Angularjs 中的单选按钮值。有没有办法获取选定的单选按钮值。我正在使用 SweetAlert v1.1.3ngSweetAlert 指令。

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");
    }
});

给你 - http://jsbin.com/lonotipeba/edit?js,output

我认为 sweetAlert 将 display:none 应用于输入元素。很抱歉大单选按钮,你可以用你的 CSS 来控制。当您单击下载按钮时,您将在 JS 警报中看到无线电的值。

您可以在 SweetAlert 中传递 function 来实现您的目标。

P.S 使用 JS 按钮点击 运行 以查看 sweetAlert 。