我使用下面的代码来显示一个确认框。
protected void cmbPayerBucketMain_SelectedIndexChanged(object sender, EventArgs e)
{
ClientScriptManager CSM = Page.ClientScript;
if (!String.IsNullOrEmpty(hiddenF1.Value) || !String.IsNullOrEmpty(hiddenF2.Value))
{
CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", "show();", true);
}
//Some Code
}和函数show(),如下所示
function show()
(
if(confirm('Chnages you made will be lost. Do you want to continue?'))
{ return true; }
else
{ return false;
}
return
)但是不管我从确认框中选择了什么选项,它都会执行整个代码。并在执行完整个事件代码后,弹出msg框。如何限制组合框等待确认框的响应,并仅当用户选择“确定”(或“是”)时才执行事件代码,并提示我如何更改确认框中按钮的文本。我想将此设置为是,取消为否)。
发布于 2013-03-16 15:00:44
不能在确认对话框中更改按钮的文本。它们内置在浏览器中。
如果你想对对话框进行更多的控制,可以使用jQuery UI中的Dialog,但它不允许你阻塞UI线程进行输入,也就是说,你不能做一些像confirm(...)这样简单的事情,然后在下一行得到结果。我建议您阅读一些文档,了解如何处理用户与对话框交互的结果。特别是,请参阅文档中的this example。我将尝试在这里改编一些简单的例子:
<script>
$(function() {
$( "#dialog-confirm" ).dialog({
resizable: false,
height:140,
modal: true,
buttons: {
"Yes": function() {
// whatever you want to run when user clicks 'yes'.
...
$( this ).dialog( "close" );
},
"No": function() {
$( this ).dialog( "close" );
}
}
});
});
</script>
<div id="dialog-confirm">
...
</div>只有一个小问题。如果您选择使用内置的确认对话框,则可以将代码简化为
function show() {
return confirm('Chnages you made will be lost. Do you want to continue?');
}发布于 2013-03-16 15:16:51
它正在执行这个函数中的所有代码,因为它不是一个函数。您使用的是括号(),而不是大括号{}。还有方法p.s.w.g。建议返回值更好。
function show() {
return confirm('Changes you made will be lost. Do you want to continue?');
} // use curly braces, not parens here发布于 2013-03-16 15:20:04
请尝试使用以下代码进行确认框自定义。
<script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="../Scripts/jquery.confirm.js" type="text/javascript"></script>
<script type="text/javascript">
function ShowConfirm(Title, Message, OkBtnCaption, CancelBtnCaption, ButtonID) {
var elem = $(this).closest('.item');
$.confirm({
'title': Title,
'message': Message,
'buttons': {
OkBtnCaption: {
'class': 'blue',
'action': function () { $('#' + ButtonID).click(); },
'id': 'okBtn'
},
CancelBtnCaption: {
'class': 'gray',
'action': function () { },
'id': 'cancelBtn'
}
}
});
return false;
}
</script>希望能有所帮助。
谢谢,湿婆
https://stackoverflow.com/questions/15446481
复制相似问题