Question:
How can I customize the confirm , replacing the Ok and Cancel button text? I also wanted to run the function only if I click Ok.
Follow the code below without success
<script> function funcao_a() { confirm('funcao A'); } function funcao_b() { alert('funcao B'); } </script> <button id="btn" onclick="confirm('Confirmar?',funcao_b());">Clique aqui</button>
Thanks
Answer:
With the native function you can't create custom checkboxes , you can however use jquery UI to simulate this:
function funcao_b() {
alert('funcao B');
}
function confirmar() {
$( "#dialog-confirm" ).dialog({
resizable: false,
height: "auto",
width: 400,
modal: true,
buttons: {
"Yap executa função b": function() {
$( this ).dialog( "close" );
funcao_b();
},
'Não executa nada': function() {
$( this ).dialog( "close" );
console.log('cancelado');
}
}
});
}
<link href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<button id="btn" onclick="confirmar();">Clica</button>
<div id="dialog-confirm" title="Executar função?"></div>