js js函数给全局变量赋值内变量总提示 is not defined

js函数参数传递-uncaught reference error len is not defined
function auto() {
& & & & timer = setInterval(function() {
& & & & & & & & index++;
& & & & & & & & if (index &= len) {
& & & & & & & & & & & & index = 0;
& & & & & & & & }
& & & & & & & & change(index);
& & & & }, 2000);
}
function focus(wrap, pic, list, prev, next, isAuto) {
& & & & var pic = $(pic),
& & & & & & & & prev = $(prev),
& & & & & & & & next = $(next),
& & & & & & & & index = 0,
& & & & & & & & timer = null,
& & & & & & & & len = pic.getElementsByTagName('li').
& & & & & & & & console.log(len);
& & & & & & & &
& & & & if (isAuto) {
& & & & & & & & auto();
& & & & & & & & if (wrap) {
& & & & & & & & & & & & var wrap = $(wrap);
& & & & & & & & & & & & wrap.onmouseover =
& & & & & & & & & & & & wrap.onmouseout =
& & & & & & & & }
& & & & & & & & if (prev && next) {
& & & & & & & & & & & & prev.onmouseover =
& & & & & & & & & & & & next.onmouseover =
& & & & & & & & & & & & prev.onmouseout =
& & & & & & & & & & & & next.onmouseout =
& & & & & & & & }
& & & & if (prev && next) {
& & & & & & & & next.onclick = function() {
& & & & & & & & & & & & index++;
& & & & & & & & & & & & if (index &= len) {
& & & & & & & & & & & & & & & & index = 0;
& & & & & & & & & & & & }
& & & & & & & & & & & & console.log(pic);
& & & & & & & & & & & & change(index);
& & & & & & & & & & & & console.log(pic);
& & & & & & & & }
& & & & & & & & prev.onclick = function() {
& & & & & & & & & & & & index--;
& & & & & & & & & & & & if (index & 0) {
& & & & & & & & & & & & & & & & index = len - 1;
& & & & & & & & & & & & }
& & & & & & & & & & & & change(index);
& & & & & & & & }
& & & & /*
& & & & if (list) {
& & & & & & & & list = $(list).getElementsByTagName('li'),
& & & & & & & & for (var i = 0; i & i++) {
& & & & & & & & & & & & list[i].title =
& & & & & & & & & & & & list[i].onmouseover = function() {
& & & & & & & & & & & & & & & & change(this.title);
& & & & & & & & & & & & }
& & & & & & & & }
& & & & }
*/
}复制代码调用了auto()之后,auto中的len总是提示未定义;(focus函数中的len显示了值5)
如果要把len作为全局变量应该在function外定义,或者把focus里的len作为参数传给auto
如果要把len作为全局变量应该在function外定义,或者把focus里的len作为参数传给auto
len在主函数中定义,不应该属于全局变量吗?为什么在子函数中会是未定义呢?
作用域 作用域&&作用域 还是作用域
你这是两个不同的函数吧。。。。
如果要把len作为全局变量应该在function外定义,或者把focus里的len作为参数传给auto
把auto放到focus里面了,好了;非常感谢;
上海联接信息技术有限公司薪金:面议职位:【Java工程师/前端开发工程师】
深圳市凡趣科技有限公司薪金:180000(元/年)职位:测试工程师
深圳市迅雷网络科技有限公司薪金:面议职位:web前端技术主管/经理js代码IE提示缺少标识符ff提示函数changeTableStyleisnotdefined(没有定义)-Web开发/JavaScript-javascript-电脑编程网js代码IE提示缺少标识符ff提示函数changeTableStyleisnotdefined(没有定义)-Web开发/JavaScript作者:shenhai11 和相关&& if (hasGongXuTable){& this.divZuJianList.InnerHtml += &onclick=\&changeTableStyle('& + xiangMuHao + &','& + GongShu + &','& + XuShu + &','tb& + xiangMuHao + &GY','tb& + xiangMuHao + &CG');\&&;&}function changeTableStyle(xiangMuHao,gongSu,xuSu,gongyingTableId,caigouTableId){&
var xmLine = document.getElementById(&trxm& + xiangMuHao);&
var xmLineStyle = document.getElementById(&tdxm& + xiangMuHao );& & &
if(xmLine.style.display == &none&)&
xmLine.style.display=&&;&
xmLineStyle.src = &../Images/minus.gif&;&
if(currentTableId == &&)&
if(gongSu&0)&
displayPageGY(xiangMuHao,0,gongyingTableId);&
if(xuSu&0)&
displayPageCG(xiangMuHao,1,caigouTableId);&
xmLine.style.display=&none&;&
xmLineStyle.src = &../Images/plus.gif&;&
}}------回答---------------其他回答(10分)---------你看看函数changeTableStyle 是不是先调用后定义啊?------其他回答(10分)---------把js定义放到head标记中再试试。这种情况,大部分都是由于调用的时候,元素还没有出现造成的相关资料:|||||||js代码IE提示缺少标识符ff提示函数changeTableStyleisnotdefined(没有定义)-Web开发/JavaScript来源网络,如有侵权请告知,即处理!编程Tags:                &                    js中提示$ is not defined_小组_ThinkSAAS
js中提示$ is not defined
js中提示$ is not defined
1.查看是否没引入jQuery的js
2.如果引入了,查看是否顺序错了,jQuery的js一定要在最前面
PHP开发框架
缓存Memcache
服务器环境
ThinkSAAS商业授权:
ThinkSAAS为用户提供有偿个性定制开发服务
ThinkSAAS将为商业授权用户提供二次开发指导和技术支持
手机客户端
ThinkSAAS接收任何功能的Iphone(IOS)和Android手机的客户端定制开发服务
让ThinkSAAS更好,把建议拿来。查看: 3152|回复: 22
请教借用redirector.uc.js中外部引用js的方法,出现window is not defined的错误
本帖最后由 jasonshaw 于
22:54 编辑
就是想要将扩展的配置分离出去,一直没有找到合适的教程,发现自己用的坛上某位大神写的
redirector.uc.js的功能可以引入外部脚本,并且可以实现不重启加载,于是就试图借用下面这段代码:[JavaScript] 纯文本查看 / 双击代码区域 Ctrl+A快速复制//载入规则
loadRule : function () {
var aFile = Cc[&@mozilla.org/file/directory_1&].getService(Ci.nsIDirectoryService).QueryInterface(Ci.nsIProperties).get('UChrm', Ci.nsILocalFile);
aFile.appendRelativePath(this.sitesFile);
if (!aFile.exists() || !aFile.isFile()) {this.alert(&Profile Error:\n\&_batchimagesdownloader.js\& can't be found!&);}
var fstream = Cc[&@mozilla.org/network/file-input-1&].createInstance(Ci.nsIFileInputStream);
var sstream = Cc[&@mozilla.org/s1&].createInstance(Ci.nsIScriptableInputStream);
fstream.init(aFile, -1, 0, 0);
sstream.init(fstream);
var data = sstream.read(sstream.available());
data = decodeURIComponent(escape(data));
} catch (e) {}
sstream.close();
fstream.close();
if (!data)
this.alert(&Profile Error:\n\&_batchimagesdownloader.js\& can't be loaded!&);
var sandbox = new Cu.Sandbox(new XPCNativeWrapper(window));//只有这里可能对window有影响
Cu.evalInSandbox(data, sandbox, &1.8&);
} catch (e) {
this.sites = sandbox.
alert(this.sites.moko.startReg);
其中this.sitesFile,是我定义的引入文件的路径,然后执行这段函数的时候,确实可以引入外部的js,并且正确赋值给我需要的对象的属性(this.sites),但是下面再执行我的扩展的时候,就无法正常执行了
错误信息是:
时间戳: 22:48:20
错误: ReferenceError: window is not defined
源文件:chrome://batchimagesdownloader/content/overlay.js
我就不执行上面的那个函数,直接使用我自己的脚本的任意内容都没有提示错误,删除上面的函数也一切正常
请教,到底那个函数的引用和执行 为何会 造成 window is not defined?
上面的代码中看到 涉及到 window的 只有第18行,我看了 sandbox的api还有XPCNativeWrapper的说明,都是没有闹明白,这个到底是什么意思?怎么就会影响原来的window呢?
该如何解决呢?
new Cu.Sandbox(new XPCNativeWrapper(window))&&这是一个安全隔离的沙盒,无法访问外部对象
原作者不是出了配置分离版本了吗?
new Cu.Sandbox(new XPCNativeWrapper(window))&&这是一个安全隔离的沙盒,无法访问外部对象
那请教这句话的完整含义是什么?
对外部的window产生了什么影响?
如何能让其他的部分顺利使用window对象,而不出现 not defined的错误呢?
new Cu.Sandbox(new XPCNativeWrapper(window))&&这是一个安全隔离的沙盒,无法访问外部对象
顺道问问 原来的那个uc脚本里面 还在最顶部做了三个引入的,不知道我仅仅用它的loadRule函数,也需要这三句吗?
[JavaScript] 纯文本查看 / 双击代码区域 Ctrl+A快速复制Cu.import(&resource://gre/modules/XPCOMUtils.jsm&);
Cu.import(&resource://gre/modules/Services.jsm&);
Cu.import(&resource://gre/modules/NetUtil.jsm&);
new Cu.Sandbox(new XPCNativeWrapper(window))&&这是一个安全隔离的沙盒,无法访问外部对象
还有就是,我执行那个loadRule方法的时候js没有任何报错
执行之后,外面的其他方法,我再运行才报错 window is not defined
还有就是,我执行那个loadRule方法的时候js没有任何报错
执行之后,外面的其他方法,我再运行才报错 win ...
我不知道你是怎样的,你这样载入,最好不要有 function
在3个Cu.import下面加const module =
再改成new Cu.Sandbox(module);
扩展中使用貌似要改成这样!
在3个Cu.import下面加const module =
再改成new Cu.Sandbox(module);
我是这样引用那段脚本的
[JavaScript] 纯文本查看 / 双击代码区域 Ctrl+A快速复制var aa = {
method1 : function(){……},
method2 : function(){……},
loadRule : function(){……},
请教那三个 引用需要放在哪里?
另外,能否解释一下这三个引用都是为具体哪个函数的调用做储备的?
还有 那个增加的部分是什么意思?
我不知道你是怎样的,你这样载入,最好不要有 function
我是这样使用的:
var aa = {
method1 : function(){……},
method2 : function(){……},
loadRule : function(){……},
比如通过method1 调用了loadRule的方法,没有报错,引入了rule给了 aa 某个属性aa.att赋值成功了
然后用method2引用上面赋值成功的aa.att,结果就报错了 window is not defined
Copyright & KaFan & All Rights Reserved.
Powered by Discuz! X3.1( 苏ICP备号 ) GMT+8,1132人阅读
//是否存在指定函数
function isExitsFunction(funcName){
if(typeof(eval(funcName))==&function&){
}catch(e){
//是否存在指定变量
function isExitsVariable(variableName){
if(typeof(variableName)==&undefined&){
//alert(&value is undefined&);
//alert(&value is true&);
}catch(e){
http://blog.csdn.net/liang4571231/article/details/4042519
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:177431次
积分:2816
积分:2816
排名:第6661名
原创:100篇
评论:24条
(1)(5)(3)(1)(4)(6)(10)(3)(5)(5)(4)(7)(12)(8)(12)(10)(10)(2)(1)}

我要回帖

更多关于 js获取函数内部变量 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信