3

完全に機能するsweeAlertプラグインを試しましたが、確認後にデフォルトのものを実行する方法がわかりません。

$(document).ready(function () {
function handleDelete(e){
    e.preventDefault();
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover the delaer again!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete!",
        closeOnConfirm: false
    },
    function (isConfirm) {
        if (isConfirm) {
            return true;
        }
    });
};
});

そしてボタン

 <a href="{plink delete! $row->id_dealers}" class="delete" onclick"handleDelete(event);">&nbsp;</a>
 //{plink delete! $row->id_dealers} Nette -> calls php delete handler

私も試してみましたがunbind()off()代わりにreturn false、動作しません。以前にconfirm()withreturn trueおよびreturn falseinonclick属性を使用しましたが、機能しますが、見栄えが悪くなります。

4

3 に答える 3

5

このようなものを試すことができます

$(document).ready(function () {
  $('.delete').on('click',function(e, data){
    if(!data){
      handleDelete(e, 1);
    }else{
      window.location = $(this).attr('href');
    }
  });
});
function handleDelete(e, stop){
  if(stop){
    e.preventDefault();
    swal({
      title: "Are you sure?",
      text: "You will not be able to recover the delaer again!",
      type: "warning",
      showCancelButton: true,
      confirmButtonColor: "#DD6B55",
      confirmButtonText: "Yes, delete!",
      closeOnConfirm: false
    },
    function (isConfirm) {
      if (isConfirm) {
        $('.delete').trigger('click', {});
      }
    });
  }
};

ここにデモhttp://jsbin.com/likoza/1/edit?html,js,outputがあります

別の方法は、の代わりにフォームを使用することhrefです。

マークアップは次のようになります

<form action="">
  <input type="submit" ...... />
</form>

代わりに、window.location = $(this).attr('href');ただ言うことができますform.submit()


アップデート

ページに複数の要素がある場合、トリガーは次のように使用できます

$(e.target).trigger('click', {});

ここにデモがありますhttp://output.jsbin.com/likoza/2

于 2015-05-24T01:19:02.013 に答える