请教对JS面向对象编程比较在行的朋友。内详
<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)
{
}
-----------------------------------------------------------------