如何处理中的body onload事件标签

发布于 2024-11-15 01:37:28 字数 491 浏览 5 评论 0原文

我在我们的应用程序中使用 sitemesh。在装饰器jsp中,我在head和body标签中添加了

<body onload="<decorator:getProperty property='body.onload'/>" >

所以我想在我的jsp页面上处理bodyonload。 我添加了以下内容:

<script type="text/javascript">
    function init() {
        alert("hi");
    }
</script>
</head>
<body onload="javascript:init();">

但是 init() 在我的 jsp 页面中不起作用。

I am using sitemesh in our application. In decorator jsp I have added <decorator:head> in head and on body tag:

<body onload="<decorator:getProperty property='body.onload'/>" >

So I want to handle body onload on my jsp page.
I have added following things:

<script type="text/javascript">
    function init() {
        alert("hi");
    }
</script>
</head>
<body onload="javascript:init();">

But init() does not worked in my jsp page.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

因为看清所以看轻 2024-11-22 01:37:28

为什么不将其全部粘贴到 script 元素中呢?比乱搞元素属性要干净得多:

window.onload = function() {
    alert('hi');
};

或者,保留 init 声明:

window.onload = init;

Why not just stick it all into the script element? Much cleaner than mucking about with element attributes:

window.onload = function() {
    alert('hi');
};

Or, alternatively, keeping the init declaration:

window.onload = init;
剩一世无双 2024-11-22 01:37:28

试试这个

<script type="text/javascript">
    function init() {
        alert("hi");
    }
</script>
</head>
<body onload="init();">

try this

<script type="text/javascript">
    function init() {
        alert("hi");
    }
</script>
</head>
<body onload="init();">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文