Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过body标记中的onload属性将数组从jsp传递给js文件中的函数_Javascript_Html_Jsp - Fatal编程技术网

Javascript 通过body标记中的onload属性将数组从jsp传递给js文件中的函数

Javascript 通过body标记中的onload属性将数组从jsp传递给js文件中的函数,javascript,html,jsp,Javascript,Html,Jsp,我有一个jsp和一个js文件。我想通过body标记中的onload属性将数组从jsp传递到js文件中的函数。我该怎么做 例如: <head> <script language="javascript" type="text/javascript"> var indexNames = ['chIndex', 'recordIndex']; var indexLocation = [0, 1]; </script> <

我有一个jsp和一个js文件。我想通过body标记中的onload属性将数组从jsp传递到js文件中的函数。我该怎么做

例如:

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

var indexNames=['chIndex','recordIndex'];
var指数定位=[0,1];
输出不正确,我认为$indexNames和$indexLocation不是传递数组的正确方法

当然,在这种情况下,我可以将数组值分离为多个参数。我只是想让javascript函数更加通用。提前谢谢

肯尼思

<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>

var indexNames=['chIndex','recordIndex'];
var指数定位=[0,1];
window.onload=函数(){
addRowHandlers('row',2,indexNames,indexLocation);
}
hm.我不懂jsp
但是您的示例不起作用,因为它是javascript。
А和onload函数中的js机器不知道$INDEXNAME和$indexLocation变量是什么。
如果只想在函数中传递数组,请执行以下操作:

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

我的问题是将$添加到变量中。谢谢