<html>
<head>
<script type="text/javascript">
function HelloWorld(){} ; HelloWorld.prototype = { 'msg' : 'Hello World !' ,
'say' : function(){
alert(this.msg) ;
}
} ;
window.onload = function(){
var hw = new HelloWorld() ;
document.getElementById('b1').onclick = hw.say ;
}
</script>
</head>
<body>
<input type="button" id='b1' value="显示信息">
</body>
</html>
不能显示Hello World ! 信息 如何显示???
<head>
<script type="text/javascript">
function HelloWorld(){} ; HelloWorld.prototype = { 'msg' : 'Hello World !' ,
'say' : function(){
alert(this.msg) ;
}
} ;
window.onload = function(){
var hw = new HelloWorld() ;
document.getElementById('b1').onclick = hw.say ;
}
</script>
</head>
<body>
<input type="button" id='b1' value="显示信息">
</body>
</html>
不能显示Hello World ! 信息 如何显示???
解决方案 »
- 属性“DownLoadMaterial”的值为 null、未定义或不是 Function 对象
- 请教javascript中读取数据库一列内容并以select下拉菜单的形式显示
- js新建层为何在FF下无效?
- js问题
- 字符串匹配-正值表达式问题
- 不同IE版本对js兼容性问题,js时间控件
- jquery.datatables 查询问题 等高手。
- 大家在进行客户端的WEB开发时都用到了哪些技术? JS ,HTC,XML 还有什么?
- this.evnt.offsetHeight 这句话是什么意思?evnt又是什么属性?
- JQuery中easyui-combobox控件怎么从后台获取数据,然后加载到combobox控件里面去
- 生成下拉菜单项的奇怪问题
- 请问:怎么在父页面上控制iframe中的字体大小?
這個語句把button b1的click事件定義為hw.say , 那麼進入在hw.say方法裏面,this代表的不再是hw對象,而是button b1.<html>
<head>
<script type="text/javascript">
function HelloWorld(){} ; HelloWorld.prototype = { 'msg' : 'Hello World !' ,
'say' : function(){
alert(this.msg)
}
} ;
window.onload = function(){
document.getElementById('b1').onclick = function(){
var hw = new HelloWorld() ;
hw.say() ;
}
}
</script>
</head>
<body>
<input type="button" id='b1' value="顯示信息">
</body>
</html>
可用分等级:奴隶
哈哈