Custom choices in JavaScript confirm dialog

后端 未结 4 1373
情深已故
情深已故 2020-11-27 22:22

How to write a confirm dialog in JavaScript with custom choices?

Instead of just "Ok" and "Cancel", I would like to have for example "This&qu

4条回答
  •  失恋的感觉
    2020-11-27 23:00

    // custom Confirm builder
    function OnConfirm(text, func) {
    
        var _confirm = $('
    ').addClass('confirm'); _confirm.append($('

    ').text(text)); _confirm.append('

    '); var _btnCancel = $('').attr('type', 'button').val('cancel') .bind('click', function () { $(this).parent('.confirm').hide(); func(false); }); var _btnApply = $('').attr('type', 'button').val('OK') .bind('click', function () { $(this).parent('.confirm').hide(); func(true); }); _confirm.append(_btnCancel); _confirm.append(_btnApply); $('body').append(_confirm); } $(function () { // documen.loaded $('#testLink').click(function (e) { e.preventDefault(); ; var _href = $(this).attr('href'); var _title = $(this).attr('title'); // call custom confirm function with callback function OnConfirm(_title, function (_isContinue) { if (_isContinue) { location.href = _href; } } ); }); });

提交回复
热议问题