javascript面向对象编程问题

zhwb36 2005-11-03 03:48:30
这样定义一个js类
function TestClass(oForm) {
this.property1 = 1;
this.property = 2;

oForm.onsubmit = function() {
//validate line
}
}

想问一下在validate line以后即onsubmit处理代码中要访问TestClass的property1,property2怎么搞?
...全文
162 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
fantiny 2005-11-03
  • 打赏
  • 举报
回复
<SCRIPT LANGUAGE="JavaScript">
<!--
function TestClass() {
this.property1 = 1;
this.property = 2;

//validate line
this.show = function a() {
for( obj in this){
document.write( obj + " = " + this[obj] + "<br>" + "\n" );
}
return ;
}
}
document.write( "=============== objtest ==============" + "<br>" + "\n" );
var objtest = new TestClass();
objtest.property1 = 2;
objtest.show();

document.write( "================= objtest1 =============" + "<br>" + "\n" );

var objtest1 = new TestClass();
objtest1.property1 = 10000000000;
objtest1.property = 10000000000;
objtest1.show();

document.write( "================ objtest2 ===========" + "<br>" + "\n" );

var objtest2 = new TestClass();
objtest2.show();
//-->
</SCRIPT>
meizz 2005-11-03
  • 打赏
  • 举报
回复
<form name=ff><input type=submit></form>

<SCRIPT LANGUAGE="JavaScript">
<!--
function TestClass(oForm) {
this.property1 = 1;
this.property = 2;
TestClass.handle = this;

oForm.onsubmit = function() {
alert(TestClass.handle.property1);
return false;
//validate line
}
}
var a = new TestClass(document.ff);
//-->
</SCRIPT>
hhubon 2005-11-03
  • 打赏
  • 举报
回复
function TestClass(oForm) {
this.property1 = 1;
this.property = 2;
property1 = this.property1;
property2 = this.property2;
oForm.onsubmit = function() {
//validate line
alert(property1);
}
}
zhwb36 2005-11-03
  • 打赏
  • 举报
回复
楼上的可能还是没搞清楚,我这段代码是写在TestClass类里面的
hbhbhbhbhb1021 2005-11-03
  • 打赏
  • 举报
回复
//一样
oForm.onsubmit = function() {
var objtest = new TestClass(oForm);
alert (objtest.property1 );
}
yjihc999 2005-11-03
  • 打赏
  • 举报
回复
CSS滤镜问题?
怎样在ASP中使表格(页面)有翻页的效果?
zhwb36 2005-11-03
  • 打赏
  • 举报
回复
楼上的可能搞错了,我是说在
oForm.onsubmit = function() {
//validate line
}
括号中的代码中如何访问类的属性
fantiny 2005-11-03
  • 打赏
  • 举报
回复
不好意思,忘了带参数。
fantiny 2005-11-03
  • 打赏
  • 举报
回复
var objtest = new TestClass();
alert (objtest.property1 );

87,921

社区成员

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

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