[英]Code to ask yes/no question in javascript
我只能找到提供確定/取消按鈕的功能confirm()
。 有沒有辦法給是/否按鈕?
沒有。
相反,您可以使用瀏覽器模式彈出窗口。
對於這類事情,我是jQuery UI Dialog的粉絲。 這是一個示例...
<script>
$(function() {
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Yes": function() {
$( this ).dialog( "close" );
alert("You chose Yes!");
},
"No": function() {
$( this ).dialog( "close" );
alert("You chose No!");
}
}
});
});
</script>
<div id="dialog-confirm" title="Are you sure you want to continue?">
<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
</div>
我會使用sweetalert https://sweetalert.js.org/guides/來實現這樣的事情
swal("Are you sure you want to do this?", { buttons: ["yes", "no"], });
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
使用對話框顯示是或否
<div id="dialog_box" class="mnk-modal-bg" style="display:none">
<div id="dbg" class="mnk-modal-box">
<i class="uk-icon-exclamation-triangle" style="color:#757575; padding-right:5px;">
</i>Confirm?
<div class="uk-text-center" style="margin-top:10px;">
<button class="md-btn md-btn-small md-btn-primary" id="ok_btn">
<i class="uk-icon-save" style="padding-right:3px;"></i>OK
</button>
<button class="md-btn md-btn-small md-btn-danger" id="close_btn">
<i class="uk-icon-remove" style="padding-right:3px;"></i>Cancel
</button>
</div>
</div>
<script>
$("#ok_btn").click(function(){
alert("OK");
$("#dialog_box").hide();
});
$("#close_btn").click(function(){
alert("CANCEL");
$("#dialog_box").hide();
});
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.