简体   繁体   English

如何在页面加载事件中调用JavaScript函数?

[英]How to call a JavaScript function on page load event?

I am calling a JavaScript function in a page to load an event as follows: 我正在页面中调用JavaScript函数以加载事件,如下所示:

Page.ClientScript.RegisterStartupScript(this.GetType(), "Script12", "Disable();", true);

The Disable() function is: Disable()函数为:

function Disable() {
   var ed = tinyMCE.activeEditor;
   ed.getBody().setAttribute('contenteditable', false);
}

But, when my page loads, it is not working as intended. 但是,当我的页面加载时,它无法按预期工作。 Are there any obvious errors in my code? 我的代码中是否有任何明显的错误? Is my Disable() function implemented correctly? 我的Disable()函数是否正确实现?

You can use jQuery ready function. 您可以使用jQuery ready函数。 Just include the reference of jQuery library (http://docs.jquery.com/Downloading_jQuery) in your page & call like this. 只需在您的页面中包含jQuery库的参考(http://docs.jquery.com/Downloading_jQuery),然后像这样调用即可。

<script src="../jquery-1.7.1.min.js"></script>
<script>
$(function() {
 Disable();
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM