开发者

How to handle body onload event in <head> tag

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.


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;


try this

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜