<input type="button" value="动态" onclick="add()" />前面也定义了
var interval;
function add() {
interval = setInterval('init()', 1000);
}
却提示:Microsoft JScript 运行时错误: “add”未定义。
百思不得其解,求教各位大神@!!!
var interval;
function add() {
interval = setInterval('init()', 1000);
}
却提示:Microsoft JScript 运行时错误: “add”未定义。
百思不得其解,求教各位大神@!!!
function add() {
interval = setInterval('init()', 1000);
}
<input type="button" value="动态" onclick="add()" />
这样试试~~
第一:格式问题<input type="button" value="动态" onclick="add()" />
<script type="text/javascript">
var interval;
function add() {
interval = setInterval('init()', 1000);
}
</script>
第二:确保定义了init函数
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
span{border:1px solid red;padding:3px 10px;}
</style>
</head>
<body>
<input type="button" value="Add" onclick="Add()" />
<input type="button" value="Stop" onclick="Stop()" />
<span>0</span>
</body>
</html>
<script language="javascript" type="text/javascript">
var interval;
var testValue = 1;
var oSpan = document.getElementsByTagName("span")[0];
function Add() {
interval = setInterval("Init()", 1000);
}
function Init() {
oSpan.innerHTML = testValue;
testValue++;
}
function Stop() {
clearInterval(interval);
}
</script>