有高手可以给一个javascript用面向对象方法编程的完整例子吗?

qiqid 2003-08-20 09:18:56
如题.
我是菜菜鸟,这个方面不怎么懂.
希望能给个完整的HTML例子,不要只有javascript那部分.
谢谢大家.
...全文
30 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wjcking 2003-08-21
  • 打赏
  • 举报
回复
//*********************我这个你看看怎么样*******************************
<script language="javascript">
function CarSpeed(intSpeed) //这是车子行驶的速度,是car函数的一个方法
{
if(intSpeed<=0||!this.Engine)//如果引擎没有发动,或者引擎发送了,没有行驶速度就为0
return "not run";

else if(intSpeed>0&&intSpeed<=50)如果车子在0--50脉速度,那么车子的速度为中速。
return "middle speed";

else if(intSpeed>50&&intSpeed<=100)//依此类推
return "high speed";

else if(intSpeed>100)
return "Super speed";

}

function Car(Cc,Ce) //车子的函数0
{
this.Color=Cc; //这里是车子的颜色
this.Engine=Ce; //引擎是否启动
this.Speed=CarSpeed //这里就是车子的事件
return this; //返回当前对象的值
}
var obj=new Car("red",true) //用new关键字实例化
with(document) //打印车子的信息。
{
write("车的颜色为:"+obj.Color+"<br>");
write("引擎是否启动:"+obj.Engine+"<br>")
write("速度等级:"+obj.Speed(50))
}

</script>
superlgc 2003-08-21
  • 打赏
  • 举报
回复
<html>
<head>
<title>面向对象的例子</title>
</head>
<body>
<script lanaguage="javascript">
//****************Begin define Class ****************************88
function ObjectExample(name,color)
{
//define the property
this.name=name
this.color=color

//define behavier
this.show=show
}

function show()
{
window.alert("name is: "+this.name+'\'+"color is :"+this.color)
}

//*****************************End of Defining *****************************

function exam()
{
var oo=new ObjectExample('A','Red')
oo.show()
}

</script>
<a href="javascript:exam()>Test</a>
</body>
</html>

glassprogrammer 2003-08-20
  • 打赏
  • 举报
回复
<HTML>
<HEAD>
<TITLE> My first JavaScript program </TITLE>

<SCRIPT LANGUAGE = JavaScript>
function TestClass(){
this.value="N/A";
this.getValue = function (){
return this.value ;
}
this.setValue = function (v){
this.value=v;
}
}

function testFunction(){
var obj = new TestClass();
obj.setValue("Hello, world...");
window.alert(obj.getValue());
}
</SCRIPT>

</HEAD>

<BODY BGCOLOR="white">
<H1>My first JavaScript program!</H1>

<a href="javascript:testFunction()">测试</a>

</BODY>
</HTML>
liuruhong 2003-08-20
  • 打赏
  • 举报
回复
小徒弟就是看了我的文章看不懂,不知道那个兄弟指导一下这个MM?

无爱大叔 2003-08-20
  • 打赏
  • 举报
回复
既然是MM那么:
http://www.csdn.net/Develop/article/20%5C20150.shtm
liuruhong 2003-08-20
  • 打赏
  • 举报
回复
哈哈,菜菜鸟,有没有人给我的徒弟帮忙啊,这个是一个mm哦 ^=^

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧