当我单击该元素时,它不会阻止默认操作

时间:2019-04-07 01:55:59

标签: javascript jquery preventdefault

我有以下代码:

HTML:

href code

JavaScript:

$('.tombol-acc').on('click', function(e) {
  e.preventDefault();
  const href = $(this).attr('href');

  Swal.fire({
    title: 'Are you sure?',
    text: "You won't be able to revert this!",
    type: 'warning',
    showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#d33',
    confirmButtonText: 'Yes, delete it!'
  }).then((result) => {
    if (result.value) {
      document.location.href = href;
    }
  })
});

但是当我单击该元素时,它不会阻止默认操作。为什么?

0 个答案:

没有答案