焦点确认不在swal工作

时间:2018-03-23 10:39:51

标签: jquery sweetalert

我正在创建甜蜜警报模型然后在模型中打开onclick事件,默认情况下自动对焦在ok按钮中如何做到这一点?和我的案例取消按钮自动对焦

 function saveCase() {
      if (recordedFullSymptoms.length != 0 && cust_preferenceFile.patient.patientId == 0) {
          swal({
              text: "You can save the case by selecting or creating new patient.",
              buttons: {
                confirm: {
                    text: "Ok",
                    value:1
                },
                Cancel: {
                    text:"Cancel",
                    value:2
                }
             },
             focusConfirm:true,
          }).then(value=> {
            if(value==1){
              getPartialView('PatientList', this);
            }  
          })
      }
      else
      {
          swal("Please select atleast one symptom to save case.");
      }
    }

1 个答案:

答案 0 :(得分:0)

以下代码适用于我,我相信您使用的是sweetalert2,但按钮语法不正确。正确的语法应如下所示 (使用sweetalert 2版本7.17.0)

function saveCase() {
      if (recordedFullSymptoms.length != 0 && cust_preferenceFile.patient.patientId == 0) {
          swal({
              text: "You can save the case by selecting or creating new patient.",
              showConfirmButton:true,
              showCancelButton: true,
              confirmButtonText: 'Ok',
              cancelButtonText: 'Cancel',
              focusConfirm:true
          }).then(result => {
            if (result.value){
              getPartialView('PatientList', this);
            }
            else if(result.dismiss === swal.DismissReason.cancel){
               swal('Cancelled');
            }
          });
      }
      else
      {
          swal("Please select atleast one symptom to save case.");
      }
    } 

这是一个工作小提琴的链接 http://jsfiddle.net/p0rdmggu/16/