当我使用iOS的Web Logger时,Javascript中没有定义方法
当我试图将日志转储到网页时,这真的很奇怪 我有一个带有Web插件的基本应用程序(在xcode中),它允许我将日志从iPhone拉到网页 但是,不知何故,当我试图调用放置在其他js文件中的方法时,我得到的结果是:“方法”没有定义 xcode Web结构: socket.html的代码片段:当我使用iOS的Web Logger时,Javascript中没有定义方法,javascript,ios,logging,Javascript,Ios,Logging,当我试图将日志转储到网页时,这真的很奇怪 我有一个带有Web插件的基本应用程序(在xcode中),它允许我将日志从iPhone拉到网页 但是,不知何故,当我试图调用放置在其他js文件中的方法时,我得到的结果是:“方法”没有定义 xcode Web结构: socket.html的代码片段: <script type="text/javascript" src="src/js/script.js"></script> <script type="text
<script type="text/javascript" src="src/js/script.js"></script>
<script type="text/javascript">
$(document).ready(main);
// Run when document.ready fires
function main() {
$('#btnClear').click(function() {
clearTable();
});
}
....
</script>
有人知道原因吗
我在linux上完成了这个项目,一切都很好。所有的家属都很好
谢谢,这是因为范围问题,
clearTable
是在匿名函数中定义的,因此它将仅在该范围内可用
您正在尝试从另一个不可用的范围调用它
解决方案是在全局范围内定义clearTable。前
$(function() {
// ....
function onLoad() {
// ....
}
window.clearTable = function() {
// ....
}
onLoad();
});
问题:解决方案: 另一个解决方案
var clearTable, isAutoScroll; //Declare these as global variables
$(function() {
// ....
function onLoad() {
// ....
}
//note this is a function variable and there is no `var`
clearTable = function() {
// ....
}
//note there is not `var` used while defining the variable
isAutoScroll = false;
onLoad();
});
恐怕它在任何地方都不起作用,除非浏览器作用域实现中存在错误。您能确认我发布的小提琴的相同行为吗?是的,它起作用,谢谢:)您能帮我处理其他文件中启动的参数吗?我需要用同样的方法吗?在script.js中,我有$(function(){var isAutoScroll=true;…});而socket.html没有看到它。所以我需要这样写:var windows.isAutoScroll=true;由于局部作用域的原因,变量的可见性也存在同样的问题,如果要在多个变量之间共享这些变量,请将它们设置为全局变量
var clearTable, isAutoScroll; //Declare these as global variables
$(function() {
// ....
function onLoad() {
// ....
}
//note this is a function variable and there is no `var`
clearTable = function() {
// ....
}
//note there is not `var` used while defining the variable
isAutoScroll = false;
onLoad();
});