javascript 如何在没有任何事件的情况下在jsp中调用javascript的函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18104964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to call a function of javascript in jsp without any event
提问by Shubham Middha
How can i call a javascript function without any event. I have a session variable namely x. what I need is to call a javascript function demo() if the session variable is not null.
我如何在没有任何事件的情况下调用 javascript 函数。我有一个会话变量,即 x。如果会话变量不为空,我需要调用一个 javascript 函数 demo()。
<% if((String)session.getAttribute("x")!=null)
{ %> <script type="text/javascript"> demo(); </script>
<% } %>
let me know the right way of calling the demo function.
让我知道调用演示功能的正确方法。
采纳答案by rickz
If I understand you correctly, then you could use the onload event. Look at
http://www.javascriptkit.com/javatutors/event3.shtml
如果我理解正确,那么您可以使用 onload 事件。看看
http://www.javascriptkit.com/javatutors/event3.shtml