我正在尝试加载具有如下函数的脚本:
$.getScript('/js/mymy.js').done(function(){
if(readCookie('my_cookie', 'yes')){
/* do sth here */
}
});
or
$.getScript('/js/mymy.js',function(){
if(readCookie('my_cookie', 'yes')){
/* do sth here */
}
});
其中“readCookie”在 mymy.js 中定义,但我收到错误“readCookie”未定义...
Here 1 & 2我在那里得到了如何做的帮助,但它不起作用......有什么想法吗?
我使用 jQuery 1.8.0
mymy.js 确实包含一个函数:
jQuery(document).ready(function() {
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
/** There is sth much more here **/
...
/** There is sth much more here **/
});
readCookie
未定义,因为readCookie
不是全球性的;它仅在document.ready
函数作用域在mymy.js
.
通过删除使该函数成为全局函数document.ready
包装纸。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)