Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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:如何将数组参数从html脚本传递到外部JS函数_Javascript_Html_Arrays_Arguments_External - Fatal编程技术网

javascript:如何将数组参数从html脚本传递到外部JS函数

javascript:如何将数组参数从html脚本传递到外部JS函数,javascript,html,arrays,arguments,external,Javascript,Html,Arrays,Arguments,External,我对Javascript和web设计相当陌生。我正试图设计一个纯粹出于教育目的的互动网络游戏,我是一个专业的教育者。我在创建自包含Java应用程序方面的大部分编程经验 在我的HTML文档中,我有一些内部脚本,用于创建一个称为“假设”的布尔数组。我还有一个名为game.JS的外部JS脚本,它根据自己的数组(也称为假设)生成一些视觉输出,我使用调用它。我想从内部数组更新外部数组,但我尝试的都不起作用。从窗体调用内部脚本 <script> var testedhypotheses

我对Javascript和web设计相当陌生。我正试图设计一个纯粹出于教育目的的互动网络游戏,我是一个专业的教育者。我在创建自包含Java应用程序方面的大部分编程经验

在我的HTML文档中,我有一些内部脚本,用于创建一个称为“假设”的布尔数组。我还有一个名为game.JS的外部JS脚本,它根据自己的数组(也称为假设)生成一些视觉输出,我使用调用它。我想从内部数组更新外部数组,但我尝试的都不起作用。从窗体调用内部脚本

<script>
    var testedhypotheses = [];
    var hypotheses = hypArray(); //load up a boolean array of hypotheses.

function testHypothesis(theform, numTest){
    //update numbers
    theform.newhyp.value = theform.newhyp.value - numTest;

    //move hypotheses from one list to the other
    for(var i; i < numTest; i++){
        testedHypotheses.push(hypotheses.pop());
    }

    //pass the array of hypotheses to the external function. 
    updateHyp(testedHypotheses);
</script>
该功能肯定可以工作,并且项目正在从一个阵列移动到另一个阵列。但是,没有调用函数updateHyp。我尝试了很多方法,但最近的一种方法是将其包含在HTML文件中:

<script type="text/javascript"  src="game.js">
    var updateHyp = function (hypArray) {
        updateHypotheses(hypArray);

    };
</script>
在game.js中,我有以下代码:

var updateHypotheses = function(hypArray){
    var end = hypotheses.length;
    for(var i = end; i < hypArray.length; i++){
        var ind = hypotheses.length;
        var tf = hypArray[i];
        var rando = Math.random();
        var res rando < 0.5 ? 1 : 0; 
        hypotheses.push(new Hypothesis(i, tf, res));
        }       
    }
};

这段代码似乎永远不会被调用。任何帮助都将不胜感激

因为您在全局范围而不是在事件处理程序中调用它,所以脚本的顺序非常重要。请澄清放置这些不同脚本块的顺序。另外,浏览器错误控制台会说什么?或者,您的问题是:您不能在单个@DarkFalcon中同时使用src和include内联代码。很抱歉,响应延迟。我的问题是,我在使用过程中没有意识到这一点。通过汗学院学习javascript的危险。。。我给processing/js文件提供了id geneclick,然后使用js processing.getInstanceById'geneclick'.updatehypothessestedhypothes;这就成功了。