这段代码的问题

来源:百度知道 编辑:UC知道 时间:2024/05/02 18:43:13
<html>
<head>
<script type="text/javascript">

var button=null;
var button2=null;

window.onload=ini;

function ini(){
button=document.getElementById("teste");

button.onclick=this.message;

};

ini.prototype.message=function()
{
alert("Welcome guest!");
};

ini.prototype.dosomething=function()
{
alert("hello");
}
;

ini.prototype.message=function()
{
alert("Welcome guest!")
}

</script>

</head>

<body>
<input id="teste" type="button" value="View message" />
<input id="test" type="button" value="alert" />
</body></html>
恩,不错。。。
我想了解一下prototype,我觉得那蛮有意思的,不过呢,我的代码不工作,,,如果你能指正一下的话。。。

<html>
<head>
<script type="text/javascript">

var button=null;
var button2=null;

window.onload=ini;

function ini(){
button=document.getElementById("teste");
button2 = document.getElementById("test");

this.message = function() { alert("Welcome guest!"); }
this.dosomething = function() { alert("hello"); }

button.onclick=this.message;
button2.onclick=this.dosomething;

};

</script>

</head>

<body>
<input id="teste" type="button" value="View message" />
<input id="test" type="button" value="alert" />
</body></html>

------------------------------------

prototype 的实现需要一个实例化的对象

例如

***************
<script type=&