小程序怎么引用js文件解决js多文件引用

当前位置: &
html引入js文件
1.简洁界面,重要步骤提供操作提示,使用方便;2.HTML所见即所得编辑器,可以发送网页
又名HTML2EXE或Web2EXE,可以将html网页打包成exe,将HTML页面或整个网站打包加密在一
pdf转换成HTML转换器能够把pdf文档转换为HTML文件,方便用户在浏览器中浏览。pdf转
有些小伙伴喜欢用PPT做演示说明,但是万一遇见不使用PowerPoint的客户的时候,PPT
php是一种网页编程语言,可独立成模块,也能嵌入html中。
这是一套免费的Office软件,它具有Drawing(画图)、Formulas(计算)、HTMLDocument(网页文件编辑)、T
软件特点:1.在主材及设备窗口录入完物料,点汇总计算,自动生成预算文件(自动生
《文字转语音播音系统》是一款把文字转换成语音的朗读软件,是专为您服务的电脑
迅捷PDF转CAD软件是一款专门应用于CAD格式文件的转换工具,支持DWG、DXF等图纸文件
PDF修改器是一款可以对PDF文件进行随意修改的PDF修改软件.其中包括修改PDF文字
迅捷PDF文档翻译软件是一款功能强大的PDF文件翻译工具,可将整篇PDF文档翻译成
软件简介:迅捷PDF图片提取工具是一款专业提取PDF文件中所有图片的免费工具,支
据彭博社报道称,iPhone或在下一代产品中引入AR(增强现实)技术。同时,苹果将在四月
酷狗7是酷狗全新推出的酷狗7.0的正式版,酷狗7全新的界面,引人入胜的播放品质
1、加入专场、专题功能可以针对季节做一些活动。2、全面使用淘点金2.0版。3、引入风格系
单词风暴2016免费版在记忆中首次引入头脑风暴,激发大脑潜能,极大地提高使用
不知道大家是否遇到过在使用office Word办公软件的过程中,输入中文双引号变成
我们在使用android studio开发编程时,可能会需要链接引入第三方类库jar包,其实我
ckeditor是fckeditorhtml编辑器了一个升级版本,用过fckeditor的站长都知道,由于其打开
网易邮箱、新浪邮箱、QQ邮箱的html在线编辑器(几款很实用的编辑器发布使用)比较适
小编推荐-html引入js文件怎么防止同样一个js文件被引入多次
[问题点数:20分,结帖人roro5119]
怎么防止同样一个js文件被引入多次
[问题点数:20分,结帖人roro5119]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2018年1月 Web 开发大版内专家分月排行榜第一2017年12月 Web 开发大版内专家分月排行榜第一2017年6月 Web 开发大版内专家分月排行榜第一2017年2月 Web 开发大版内专家分月排行榜第一2016年3月 Web 开发大版内专家分月排行榜第一2015年8月 Web 开发大版内专家分月排行榜第一
2018年4月 Web 开发大版内专家分月排行榜第二2018年3月 Web 开发大版内专家分月排行榜第二2018年2月 Web 开发大版内专家分月排行榜第二2017年11月 Web 开发大版内专家分月排行榜第二2017年10月 Web 开发大版内专家分月排行榜第二2017年9月 Web 开发大版内专家分月排行榜第二2017年8月 Web 开发大版内专家分月排行榜第二2017年7月 Web 开发大版内专家分月排行榜第二2017年5月 Web 开发大版内专家分月排行榜第二2017年4月 Web 开发大版内专家分月排行榜第二2017年3月 Web 开发大版内专家分月排行榜第二2017年1月 Web 开发大版内专家分月排行榜第二2016年11月 Web 开发大版内专家分月排行榜第二2016年9月 Web 开发大版内专家分月排行榜第二2016年8月 Web 开发大版内专家分月排行榜第二2016年7月 Web 开发大版内专家分月排行榜第二2016年6月 Web 开发大版内专家分月排行榜第二2016年5月 Web 开发大版内专家分月排行榜第二2016年4月 Web 开发大版内专家分月排行榜第二2016年2月 Web 开发大版内专家分月排行榜第二2015年9月 Web 开发大版内专家分月排行榜第二2015年7月 Web 开发大版内专家分月排行榜第二2015年6月 Web 开发大版内专家分月排行榜第二2015年4月 Web 开发大版内专家分月排行榜第二2015年3月 Web 开发大版内专家分月排行榜第二2015年2月 Web 开发大版内专家分月排行榜第二
2013年12月 Web 开发大版内专家分月排行榜第三
匿名用户不能发表回复!|在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。
问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
我想在js文件中使用underscore,使用npm install underscore后文件夹多了一个文件夹,下面有一个underscore文件夹,接下来应该怎么在js文件中使用underscore中的方法啊
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
const _ = require('underscore')
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
在你用之前引入该对应js文件:
&script type="text/javascript" charset="utf8" src="path/to/xxx.js"&&/script&
然后就可以使用xxx.js文件里面定义的一些函数或变量了。
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
动态创建script标签 插到页面呗~
同步到新浪微博
分享到微博?
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:
在 SegmentFault,学习技能、解决问题
每个月,我们帮助 1000 万的开发者解决各种各样的技术问题。并助力他们在技术能力、职业生涯、影响力上获得提升。04:09:20 UTC
建立了两个JS文件,一个是全局文件Alert.js,用于预制;一个是background.js那么有方法在Alert.js调用background的function吗?
06:50:41 UTC
const Bg =
require('background');Bg.function();
07:38:07 UTC
可以在Alert.js中的properties中引用你的预制资源,然后你就能用了....
07:48:26 UTC
反了,我是想在预制中用background.js中的function
07:48:46 UTC
尝试过不行提示invoking function fail
07:59:37 UTC
这个Alert.js
//全局文件Alter,随时调用prefab(需要在此js属性上勾选为插件,是它成为全局文件)
var Alert = {
_alert: null,
_closeButton:
// 取消按钮
_soundButton:
//音量按钮
_saveButton:
//存档按钮
_loadButton:
//读取按钮
_musicButton:
//关闭音乐
_animSpeed:
// 动画速度
_stopButton:
//禁用按钮
* animSpeed:
动画速度 default = 0.3.
const Bg = require("StoryBackGroundTouch");
Alert.show = function () {
var self =
if (Alert._alert != undefined)
// 加载 prefab 创建
cc.loader.loadRes("Alert", cc.Prefab, function (error, prefab) {
if (error) {
cc.error(error);
var alert = cc.instantiate(prefab);
// Alert 持有
Alert._alert =
var cbFadeOut = cc.callFunc(self.onFadeOutFinish, self);
var cbFadeIn = cc.callFunc(self.onFadeInFinish, self);
self.actionFadeIn = cc.sequence(cc.spawn(cc.fadeTo(Alert._animSpeed, 255), cc.scaleTo(Alert._animSpeed, 1.0)), cbFadeIn);
self.actionFadeOut = cc.sequence(cc.spawn(cc.fadeTo(Alert._animSpeed, 0), cc.scaleTo(Alert._animSpeed, 2.0)), cbFadeOut);
//获取按钮结点
Alert._closeButton = cc.find("Menubackground2/Close", alert);
Alert._soundButton = cc.find("Menubackground2/Sound", alert);
Alert._musicButton = cc.find("Menubackground2/Music", alert);
Alert._saveButton = cc.find("Menubackground2/Save", alert);
Alert._loadButton = cc.find("Menubackground2/Load", alert);
Alert._stopButton = cc.find("Menubackground2/CloseSound",alert);
// 添加点击事件
Alert._closeButton.on('click', self.onButtonClicked, self);
Alert._soundButton.on('click', self.onButtonClicked,self);
Alert._musicButton.on('click', self.onButtonClicked,self);
Alert._saveButton.on('click', self.onButtonClicked,self);
Alert._loadButton.on('click', self.onButtonClicked,self);
Alert._stopButton.on('click', self.onButtonClicked,self);
Alert._alert.parent = cc.find("Canvas");
//初始化按钮
Alert._stopButton.active =
// 展现 alert
self.startFadeIn();
// 执行弹进动画
self.startFadeIn = function () {
cc.eventManager.pauseTarget(Alert._alert, true);
Alert._alert.position = cc.p(0, 0);
Alert._alert.setScale(2);
Alert._alert.opacity = 0;
Alert._alert.runAction(self.actionFadeIn);
// 执行弹出动画
self.startFadeOut = function () {
cc.eventManager.pauseTarget(Alert._alert, true);
Alert._alert.runAction(self.actionFadeOut);
// 弹进动画完成回调
self.onFadeInFinish = function () {
cc.eventManager.resumeTarget(Alert._alert, true);
// 弹出动画完成回调
self.onFadeOutFinish = function () {
self.onDestory();
// 按钮点击事件(需要在prefab精灵属性上添加按钮组件)
self.onButtonClicked = function(event){
if(event.target.name == "Close"){
self.startFadeOut();
else if (event.target.name == "Music"){
Bg.pause();
Alert._musicButton.active =
Alert._stopButton.active =
else if (event.target.name == "CloseSound"){
Alert._musicButton.active =
Alert._stopButton.active =
else if (event.target.name == "Sound"){
else if (event.target.name == "Save"){
else if (event.target.name == "Load"){
// 重置Alert
self.onDestory = function () {
Alert._alert.destroy();
Alert._alert =
Alert._closeButton =
08:10:30 UTC
这个是StoryBackGroundTouch.js
// Learn cc.Class:
- [Chinese] http://www.cocos.com/docs/creator/scripting/class.html
- [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/class/index.html
// Learn Attribute:
- [Chinese] http://www.cocos.com/docs/creator/scripting/reference/attributes.html
- [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/reference/attributes/index.html
// Learn life-cycle callbacks:
- [Chinese] http://www.cocos.com/docs/creator/scripting/life-cycle-callbacks.html
- [English] http://www.cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/life-cycle-callbacks/index.html
cc.Class({
extends: cc.Component,
properties: {
//这里是字母L
audioSource: {
default: null,
type: cc.AudioSource,
default: null,
type:cc.Label,
Aronsprite:{
default:null,
type:cc.Sprite,
Liusprite: {
default: null,
type: cc.Sprite,
Magesprite: {
default: null,
type: cc.Sprite,
aronactive_string: {
//定义一个数组用于操作亚伦精灵是否显示
default: [],
type: ["String"]
liuactive_string: {
//定义一个数组用于操作老刘精灵是否显示
default: [],
type: ["String"]
mageactive_string: {
//定义一个数组用于操作夏末精灵是否显示
default: [],
type: ["String"]
leftname_string: {
//定义一个数组用于存储左边角色昵称
default: [],
type: ["String"]
rightname_string: {
//定义一个数组用于存储右边角色昵称
default: [],
type: ["String"]
story_string: {
//定义一个数组用于存储剧情文字
default: [],
type: ["String"]
onLoad: function () {
this.i = -1;
this.l = 0;
//这里是字母L
this.r = 0;
this.p = 0;
this.q = 0;
this.s = 0;
// LIFE-CYCLE CALLBACKS:
Name1: function () {
//左角色名框显示调用函数
var self =
self.label.string = this.leftname_string[this.l];
this.l = this.l + 1;
Name2: function () {
//右角色名框显示调用函数
var self =
self.label.string = this.rightname_string[this.r];
this.r = this.r + 1;
AronActive: function () {
var self =
if (this.aronactive_string[this.p] == 1) {
self.Aronsprite.enabled =
self.Aronsprite.enabled =
this.p = this.p + 1;
LiuActive: function () {
var self =
if (this.liuactive_string[this.q] == 1) {
self.Liusprite.enabled =
self.Liusprite.enabled =
this.q = this.q + 1;
MageActive: function () {
var self =
if (this.mageactive_string[this.s] == 1) {
self.Magesprite.enabled =
self.Magesprite.enabled =
this.s = this.s + 1;
Story: function () {
var self =
var index = 1;
self.schedule(function () {
self.label.string = this.story_string[this.i].substr(0,index);
index = index + 1;
}, 0.01, 100);
this.i = this.i + 1;
if (this.i == 24) {
this.node.runAction(cc.sequence(cc.fadeOut(1.0), cc.callFunc(function () {
cc.director.loadScene("Chess")
menu_click: function(){
Alert.show();
//渐入效果,新建JS文件,并且将这个文件添加到场景Story中(添加用户自定义脚本)
start () {
this.node.setOpacity(0);
this.node.runAction(cc.fadeIn(1.0));
pause: function () {
this.audioSource.pause();
resume: function () {
this.audioSource.resume();
// update (dt) {},
08:15:55 UTC
也可以在预制的属性中存你要调用的对象的引用的,不过要在其他地方将background引用传进去
01:11:46 UTC
中存你要调用的对象
楼主解决了没,我也遇到同样问题,我有一个player.js 里面封装了一个函数用来换头像setHead,然后在game.js里调用player.setHead居然不行,这什么鬼
02:25:55 UTC
你的game.js里的player是不是js文件
06:17:29 UTC
是预制体,绑定了player.js 在game.js里的属性声明是:
default: null,
type: cc.Prefab,
然后在game.js里这么用的var player = cc.instantiate(this.player);this.node.addChild(player);player.setHead();
06:20:17 UTC
是预制体,绑定了player.js 在game.js里的属性声明是:
default: null,
type: cc.Prefab,
然后在game.js里的onload()这么用的var player = cc.instantiate(this.player);this.node.addChild(player);player.setHead();
06:57:12 UTC
你的player是一个cc.Node类型,你要获取node下面的js才行,如player.getComponent('player').setHead();
10:10:11 UTC
10:12:39 UTC
你的js文件名是大写的,注意下大小写你应该写成这样 player.getComponent('Player').setHead();
你可以把js文件看成一个组件,你现在获取的是这个叫做‘Player’的组件
10:53:23 UTC
可以了,多谢多谢

我要回帖

更多关于 vue怎么引用js文件 的文章

 

随机推荐