【发布时间】:2021-05-12 18:12:51
【问题描述】:
我在 WebForms 中有一个 jQuery 脚本,我试图在按钮单击事件上显示一条消息。我的.aspx 文件中有script,我在代码隐藏中调用它。问题是如果用户点击confirm 而不是cancel 按钮,我该如何重定向?
.ASPX 脚本:
<script type="text/javascript">
$(window).unload(function () {
CloseWindow();
})
//var newEmployeeDetail = document.getElementById(hfNe)
function confirmAppointEmployee() {
debugger;
Messi.ask("Employee appointed successfully",
function (val) {
if (val == false) {
$("[id*=Cancel]").click();
}
else {
$("[id*=Confirm]").click();
}
}, {
buttons: [{ id: '0', label: 'Confirm', val: true, 'class': 'btn-primary' }, { id: '0', label: 'Cancel', val: false }]
});
}
</script>
代码背后:
ClientScript.RegisterStartupScript(this.GetType(), "Success", "<script>confirmQuickAppointEmployee()</script>");
下面的代码是重定向用户需要调用的字符串。
private string PersonalInformationDetailUrl = Company.Framework.SmartNavigationPersonnel.SmartNavigation.GetUrlByPageName(Company.Framework.SmartNavigationPersonnel.SmartNavigation.PageNameList.PersonalInformationDetail) + "?AllowAddOption=true&AllowDeleteOption=true&RefreshMenuPage=true";
我尝试了下面的方法,但cancel 和confirm 按钮都做同样的事情。
var confirm = "$(document).ready(function(){ new Messi('Employee appointed successfully', " +
"{title: 'Title', buttons: [{id: 0, label: 'Close', val: 'false'},{id: 0, label: 'Confirm', val: 'true'}], " +
"callback: function(val) { window.location.href = '" + Functions.FixClientUrl(PersonalInformationDetailUrl) + "' }}); });";
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "confirm", confirm, true);
【问题讨论】:
-
ID 中包含“取消”和“确认”的元素在哪里,您正在调用
click方法? -
请澄清您的问题。例如,您同时引用
confirmQuickAppointEmployee和confirmAppointEmployee函数。它们是一样的吗?此外,您将confirmQuickAppointEmployee注册为启动脚本。为什么?您的问题是关于按钮单击事件...您此时注册了另一个功能...最后但并非最不重要的一点是,您似乎正在使用 MessiJS(对吗?)。这一点很重要,因为回调函数的问题直接受该插件工作方式的影响(顺便说一句,它看起来像废弃软件:没有文档等)。所以,请把它清理干净。
标签: javascript jquery asp.net function webforms