最简单的javascript对象实例代码
作者:bea
<html> <body> <script> function user() { this.age=21; this.name="zhangsan"; this.say=function(){ alert("hello"); } } var u = new user(); alert(u["age"]); alert(u.name); u.say(); </script> </body> </html>
<html>
<body>
<script>
function user()
{
this.age=21;
this.name="zhangsan";
this.say=function(){
alert("hello");
}
}
var u = new user();
alert(u["age"]);
alert(u.name);
u.say();
</script>
</body>
</html>
[Ctrl+A 全选 注:
如需引入外部Js需刷新才能执行]
JavaScript面向对象的两种书写方法以及差别
http:///article/13211.htm
JavaScript 面向对象入门精简篇
http:///article/17541.htm
有用 | 无用
猜你喜欢
您可能感兴趣的文章:
- JQuery读取XML文件数据并显示的实现代码
- js实现页面打印功能实例代码(附去页眉页脚功能代码)
- 利用图片的 onerror 事件载入默认图片
- jQuery 渐变下拉菜单
- javascript实现的仿51job地址多项选择方式效果
- javascript 日期联动选择器 [其中的一些代码值得学习]
- js checkbox全选并将获取值放到input里边
- 多浏览器兼容的获取元素和鼠标的位置的js代码
- IE不支持option的display样式,只能使用remove和add
- 讨论javascript(一)工厂方式 js面象对象的定义方法
- 查询绑定数据岛的表格中的文本并修改显示方式的js代码
- jquery自动完成插件(autocomplete)应用之PHP版
- jQuery Attributes(属性)的使用(一、属性篇)
- Javascript attachEvent传递参数的办法
- firefox下对ajax的onreadystatechange的支持情况分析
- javascript document.execCommand() 常用解析
- JavaScript 创建随机数和随机图片
- JQuery Tips(3) 关于$()包装集内元素的改变
- JQuery Tips(2) 关于$()包装集你不知道的