我正在使用bootbox来显示对话框。当我试图将实现放在JavaScript中时它工作正常
$("#btnAdd").click(function () {
bootbox.dialog({
message: "my message.",
title: "<i class='fa fa-times-circle red'></i> Error!",
buttons: {
main: {
label: "Got It!",
className: "btn btn-success btn-primary"
}
}
});
});
在上述情况下,按钮会自动对焦,以便按Enter键关闭它。
但是,因为我有一些值作为参数插入我决定制作一个C#函数并实现它
public void ShowMessagebox(string msg,string type,Page mypage)
{
string title="";
switch(type)
{
case "success":
title="<i class='fa fa-check-circle green'></i> <span class='green'> Success!</span>";
break;
case "error":
title="<i class='fa fa-times-circle red'></i> Error!";
break;
case "info":
title="<i class='fa fa-info-circle orange2'></i> Information!";
break;
}
ScriptManager.RegisterStartupScript(mypage, this.GetType(), "myfunction", "bootbox.dialog({message: \"" + msg + "\",title: \"" + title + "\",buttons: { main: {label: \"Got It!\",className: \"btn-primary btn-success\"}}});", true);
}
现在这样可以正常工作。但我的问题是按钮没有聚焦,我无法按回车键关闭对话框。
即使我已经放了$(“。btn-primary”)。focus()但没有用!。
任何人都可以请帮助
提前致谢
答案 0 :(得分:0)
我得到了答案
我只是用jquery ready函数包装代码,它工作正常!
谢谢