我有 JQuery 函数显示通知消息。 从我的 asp.net 页面,我想在页面完全加载时调用它,例如:Request.QueryString[c_opID] != null; 我尝试使用 ScriptManager.RegisterStartupScript() 从 Page_Load 和 Page_LoadComplete 调用该函数,但该函数没有启动。另一方面,当我在按钮上调用它时,单击它会执行应该执行的操作。
JQuery 函数:
function showMessage(title, message) {
PNotify.prototype.options.styling = "jqueryui";
var notice = new PNotify({
title: title,
text: message,
type: 'success',
opacity: 1,
animate_speed: 'fast',
addclass: 'custom'
});
notice.get().click(function() {
notice.remove();
});
setTimeout(function() {
notice.remove();
}, 3000);
}
调用背后的Asp.Net代码:
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "script", @"showMessage('" + title + "','" + message + "');", true);
最佳答案
替代方案是纯js
您所需要的只是使用 javascript 从 url 获取参数。这是一种解决方案(复制自 How can I get query string values in JavaScript? )
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
然后
$(function () {
if (getParameterByName('your_parameter_name')){
// show message
}
})
关于javascript - 当asp.net页面有特定查询字符串时调用JQuery函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27165468/