开发者

Pass arrays from a jsp to a function in a js file via the onload attribute in the body tag

I have a jsp and a js files. I would like to pass arrays from the jsp to a function in the js file via the onload attribute in the body tag. How can I do that?

For example:

<head>
<script language="javascript" type="text/javascript">
        var indexNames  = ['chIndex', 'recordIndex'];
        var indexLocation = [0, 1];
    </script>
</head>
<body onload="addRowHandlers('row', 2, $indexNames, $indexLocation)">

The output is no开发者_JAVA技巧t correct and I think $indexNames and $indexLocation are not the right way to pass the arrays.

Of course, in this case, I can separate the array values into multiple parameters. I am just want to make the javascript function more general. Thanks in advance.

Kenneth


hm.i don't know jsp but your example don't work because its javascript. Аnd in onload function js machine don't know what is $indexNames and $indexLocation variable. If you want just to pass arrays in function:

<body onload="addRowHandlers('row', 2, indexNames, indexLocation)">


Something like

<head>
<script language="javascript" type="text/javascript">
        var indexNames  = ['chIndex', 'recordIndex'];
        var indexLocation = [0, 1];
        window.onload =function() {
            addRowHandlers('row', 2, indexNames, indexLocation);
        }
    </script>
</head>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜