在Submit上加载多个Javascript文件

在Submit上加载多个Javascript文件,javascript,file,function,call,Javascript,File,Function,Call,我已经定义了3个javascript文件,其中有几个函数,每个文件中都有事件处理程序onsubmit(基本上是相同的结构)。问题是,当我将这3个文件作为filepath插入正文部分的底部时,只有2个文件被加载,而第三个文件没有加载,我无法理解为什么。。。 代码如下: function init() { 'use strict'; // Listen to see whether the form has been submitted: //get a handle to

我已经定义了3个javascript文件,其中有几个函数,每个文件中都有事件处理程序onsubmit(基本上是相同的结构)。问题是,当我将这3个文件作为filepath插入正文部分的底部时,只有2个文件被加载,而第三个文件没有加载,我无法理解为什么。。。 代码如下:

function init() {
    'use strict';

    // Listen to see whether the form has been submitted:
    //get a handle to my form
    var demogrForm = document.getElementById("Demographics");   
    demogrForm.onsubmit = validateInputs;

    console.log("submit");
} // End of init() function.

window.onload = init;
console.log("init");
本质上,在3个文件中,为每个“onsubmit”调用的函数是不同的,但是处理调用的代码是相同的……你知道吗

尝试使用jQuery$(函数(){});或者更改您的window.onload。应该是这样的:

window.onload=function(){
    console.log("init");
    // Listen to see whether the form has been submitted:
    //get a handle to my form
    var demogrForm = document.getElementById("Demographics");   
    demogrForm.onsubmit = validateInputs;

    console.log("submit");
};
或者使用jQuery:

$(function(){
    console.log("init");
    // Listen to see whether the form has been submitted:
    //get a handle to my form
    var demogrForm = document.getElementById("Demographics");   
    demogrForm.onsubmit = validateInputs;

    console.log("submit");
});

对不起,由于某种原因它没有通过。代码如下:函数init(){'use strict';//侦听以查看表单是否已提交://获取我的表单var demogrForm=document.getElementById(“Demographics”);demogrForm.onsubmit=validateInputs;console.log(“submit”);//init()函数的结束。window.onload=init;console.log(“init”);这段代码是否存在于所有三个javascript文件中,只有elementId不同?好的,我已经修复了它,所以我就是这样做的:在最后一个javascript文件(我的第三个文件)中,您必须调用前面文件中定义的函数。类似//any code here}//end of function_3(如第三个文件中定义的)返回函数_1();//如第一个javascript文件返回函数_2();//中所定义正如在第二个javascript文件中定义的…等等。。。window.onload=function(){console.log(“init”);document.getElementById(“FormName”)=function_3;};这至少对我有用:)是的,window.onload=init;覆盖以前分配给window.onload的函数。不要等太久才去学习一个框架,比如jQuery:它确实让生活变得更简单。嗯……避免使用init()函数并不能让它变得更简单……我应该在window.onload=function()中调用什么函数?此外,我正在学习javascript,所以如果可能的话,我会在这个阶段避免使用框架