如何在javascrip中调用内部函数 [英] how call an inner function in javascrip
本文介绍了如何在javascrip中调用内部函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
i有一个内部函数,我用setTimeout调用它。但它不会运行。
我错了什么
谢谢
我的代码是:
hi
i have a inner function and i call its with setTimeout.but It will not run.
what''s my wrong
thank you
my code is :
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function Overrideablefunc() {
this.runfunc=function () {
document.getElementById('txt').value = Date().substring(0, 24);
setTimeout(this.runfunc, 1000);
}
}
function runnewfunc() {
var a=new Overrideablefunc()
a.runfunc();
}
</script>
</head>
<body>
<input type="button" value="Run" onclick="runnewfunc()"/><br />
<input type="text" id="txt" style="width:400px"/>
</body>
</html>
推荐答案
Overrideablefunc现在就像一个对象,你必须创建它的一个实例然后你可以调用runfunc < br $>
Overrideablefunc now acts like an object, you have to create an instance of it and then you can call runfunc
var override = new Overrideablefunc();
override.runfunc();
这篇关于如何在javascrip中调用内部函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文