用javascript自定义的函数没法用onclick事件来调用



<!doctype html>
<html>
<head>
<title>this is a test</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
<form name="frm1">
<input type="button" value="change title" onclick=" title(); ">

</form>
</center>

<script language="JavaScript">
var n=0;
function title()
{   n++;
    if(n==3){n=1;}
    if(n==1){document.title='@@@动态编码##'};
    if(n==2){document.title='☆个人主页☆'};

    setTimeout("title()",1000);


}

</script>


</body>


</html>

没看到你引用的地方啊!

函数名不要和对象内置的属性一样,要不会调用到对象的title属性(字符串),不是函数报错了,而不是window作用域下的title函数

 <input type="button" value="change title" onclick="alert(this.title);window.title(); ">
  1. > # __

你的方法名不能去title, 用个其他的名字就可以了

<!doctype html>


this is a test


var n=0; function title() { n++; if(n==3){n=1;} if(n==1){document.title='@@@动态编码##'}; if(n==2){document.title='☆个人主页☆'}; setTimeout("title()",1000); }