function btnSelete_Click() {
var strconfirm = confirm("Are you sure you want to delete?");
if (strconfirm == true) {
return true;
}
}
<asp:Button ID="btnSelect" runat="server" Text="Select" Onclientclick="return btnSelete_Click();" CssClass="cssbutton" />
如何在Javascript中创建是/否/取消警告框而不是ok / cancel警告框?
你可以使用jQuery UI Dialog。
这些库创建的HTML元素看起来和行为就像一个对话框,允许您在对话框中放置任何您想要的内容(包括表单元素或视频)。
为了解决类似的情况,我遇到了this的例子和adapted它。它使用JQUERY UI Dialog作为Nikhil D建议。这是一个代码:
HTML:
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<input type="button" id="box" value="Confirm the thing?" />
<div id="dialog-confirm"></div>
JavaScript的:
$('#box').click(function buttonAction() {
$("#dialog-confirm").html("Do you want to do the thing?");
// Define the Dialog and its properties.
$("#dialog-confirm").dialog({
resizable: false,
modal: true,
title: "Do the thing?",
height: 250,
width: 400,
buttons: {
"Yes": function() {
$(this).dialog('close');
alert("Yes, do the thing");
},
"No": function() {
$(this).dialog('close');
alert("Nope, don't do the thing");
}
}
});
});
$('#box').click(buttonAction);
我需要做一些调整才能让这个例子适用于我的应用程序。如果我认为它适合答案,将更新此。希望这有助于某人。
您不能使用本机confirm()
,因为它是浏览器的方法。
您必须为确认框创建一个插件(或尝试由其他人创建的插件)。而且它们通常看起来也更好。
附加提示:将您的英语句子改为
真的,删除这件事?
我将尝试使用jQuery的解决方案,肯定它应该给出一个很好的结果。当然你必须加载jQuery ...这样的弹出窗口怎么样?当然,这取决于用户授权弹出窗口。
<html>
<head>
<script language="javascript">
var ret;
function returnfunction()
{
alert(ret);
}
</script>
</head>
<body>
<form>
<label id="QuestionToAsk" name="QuestionToAsk">Here is talked.</label><br />
<input type="button" value="Yes" name="yes" onClick="ret=true;returnfunction()" />
<input type="button" value="No" onClick="ret=false;returnfunction()" />
</form>
</body>
</html>
Javascript中的“Confirm”会停止整个过程,直到它的按钮上出现鼠标响应。如果您正在寻找,那么您可以参考jquery-ui,但如果您在接收响应时没有在您的流程后面运行,并且您以编程方式控制流程,请查看此内容。您必须自己对所有内容进行硬编码,但您必须完全掌握自定义。 https://www.w3schools.com/howto/howto_css_modals.asp