Javascript位于底部,函数调用在体内? [英] Javascript at the bottom, function call in the body?

查看:87
本文介绍了Javascript位于底部,函数调用在体内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题,我遵循的惯例是将所有Javascript文件保留在文档底部关闭主体之前.但是我想在主体中调用一个函数,该函数会出现在JS include之前,因此会失败.

Just a quick question, I'm following the practice of keeping all Javascript files at the bottom of the document before the closing body. However I want to call a function in the body, which would appear before the JS include, and thus fails.

是否有必要使此功能正常运行而又不将文件移入头部?

Is there anyway to get this function to work without moving the files into the head?

干杯!

推荐答案

是的,您可以将函数包装为

yes you can wrap your function with

window.onload = function() {
   //call to your function here
};

,但是如果您可以修改页面底部,则此解决方案可能会更好:
停止支付jQuery税

but probably this solution is better if you can modify the bottom part of your page:
Stop paying your jQuery tax

这篇关于Javascript位于底部,函数调用在体内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆