请教对JS面向对象编程比较在行的朋友。内详

imatree 2002-11-15 09:11:28
<form name=formName method=post action='{$_MY_ENV["this_path"]}' onSubmit='return this.post();'>

post方法的功能
***.post = function()
{
alert('已经将您的设置发送。');
return true;
}

我的目的是将post作为form的方法函数来使用,做到与formName.submit()相同的调用方式。
现在唯一需要知道的就是post前面的***如何来写。请赐教...

下面是JScript5.6中的一个例子,我的意思大概也是如此了:
-----------------------------------------------------------------
// 增加一个名为 trim 的函数作为
// String 构造函数的原型对象的一个方法。
String.prototype.trim = function()
{
// 用正则表达式将前后空格
// 用空字符串替代。
return this.replace(/(^\s*)|(\s*$)/g, "");
}

// 有空格的字符串
var s = " leading and trailing spaces ";

// 显示 " leading and trailing spaces (35)"
window.alert(s + " (" + s.length + ")");

// 删除前后空格
s = s.trim();
// 显示"leading and trailing spaces (27)"
window.alert(s + " (" + s.length + ")");
-----------------------------------------------------------------


我不希望得到的答案
-----------------------------------------------------------------
1. formName.post = function(){
}

2. function post(formName)
{
}
-----------------------------------------------------------------
...全文
39 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
神鹰 2002-11-16
  • 打赏
  • 举报
回复

barrydiu 2002-11-15
  • 打赏
  • 举报
回复
没有这种方法。
JK_10000 2002-11-15
  • 打赏
  • 举报
回复
<form name=frm>

<input name=a>
<input type=button value=ok onclick="myForm.post();">


</form>
<script>
function MyForm(obj)
{
this.thisForm = obj;
this.post=postfun
function postfun()
{
alert('已经将您的设置发送。共有元素'+this.thisForm.elements.length+'个');
return true;
}
}
var myForm=new MyForm(document.frm);
</script>
wpmsoft 2002-11-15
  • 打赏
  • 举报
回复
I have no idea.
没有解的,放弃吧。
blues-star 2002-11-15
  • 打赏
  • 举报
回复
<script>
var tmp = new String("asdfasd");
alert(tmp);
</script>

String可以那么写,是因为它可以这样

<script>
var tmp = new Form();
alert(tmp);
</script>

但是form不可以这样,因为它是已经封装了的ACTIVEX

87,996

社区成员

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

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