在code呼叫的window.onload函数后面不工作 [英] Call window.onload function in code behind not working
问题描述
我写了一个js函数在ASPX像下面
I have written a js function in aspx like below
window.onload = function () {
document.getElementById('grid-overlay').style.display = 'block';
}
现在我想后面调用code此功能。我试着象下面这样: -
Now I want to call this function in code behind. I tried like below:-
if (dtmkey.Rows.Count > 0)
{
HidMode.Value = "M";
HidMKey.Value = dtmkey.Rows[0]["mkey"].ToString();
var scriptSource = "function onload() { alert(""); };\n";
ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "HelpScript", scriptSource, true); // Not working
}
好心提示什么是错
kindly suggest what is wrong
推荐答案
的window.onload
是负载的事件处理程序
A 窗口
&安培的事件;附函数
是函数
将在负荷
被称为事件。
window.onload
is an event handler for the load
event of a window
& the attached function
is function
that will be called on load
event.
此外,目前还不清楚是什么你想在这一点上做
Also it is not clear what you are trying to do at this point
// I ran this variable in console, it threw unexpected syntax
var scriptSource = "function onload() { alert(""); };\n"; //
您想在这里调用一个函数前pression?
你可以使这个修改和测试
Are you trying to call a function expression here? you can make this changes and test it
function onload(){ // This is a function expression and onload not same as window.onload
document.getElementById('grid-overlay').style.display = 'block';
}
window.onload = function () {
onload() // call onload function here once window has finished loading
}
如果您正在寻找的onload
在这里你可以替换下面段
If you are looking for onload
here you can replace the below snippet
var scriptSource = "function onload() { alert(""); };\n"; with `onload();`
这篇关于在code呼叫的window.onload函数后面不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!