<html>
<head>
<script type="text/javascript">
function ArgTest(){
var i, s, numargs = arguments.length;
s = numargs;
if (numargs < 2)
s += " argument was passed to ArgTest. It was ";
else
s += " arguments were passed to ArgTest. They were " ;
for (i = 0; i < numargs; i++)
{
s += arguments[i] + " ";
}
return(s);
}
//测试函数传入的参数的个数
function result()
{
var re = ArgTest(1,2);
alert('Arguments result:' + re);
}
//测试调用的函数体
function callLevel()
{
var callLe = result.caller;
alert(callLevel);
}
//两个方法名相同的方法,回自动适配写在后面的一个
function consta()
{
var con = new String("11").constructor;
alert("con:"+con);
}
function consta()
{
var con = new String("11").constructor;
alert("consta:"+con);
}
//测试E,以及显示函数和隐式函数
var aa = function newVar()
{
alert(Math.E);
}
//测试global属性
function RegExpPropDemo(flag){
if (flag.match(/[^gim]/)) //检查标志的有效性。
return("Flag specified is not valid");
var r, re, s //声明变量。
var ss = "The man hit the ball with the bat.\n";
ss += "while the fielder caught the ball with the glove.";
re = new RegExp("the",flag); //指定要查找的样式。
alert("re"+re);
r = ss.replace(re, "a"); //用 "a" 替换 "the"。
s = "Regular Expression property values:\n\n"
s += "global ignoreCase multiline\n"
if (re.global) //测试 global 标志。
s += " True ";
else
s += "False ";
if (re.ignoreCase) //测试 ignoreCase 标志。
s += " True ";
else
s += "False ";
if (re.multiline) //测试 multiline 标志。
s += " True ";
else
s += " False ";
s += "\n\nThe resulting string is:\n\n" + r;
alert(s);
return(s); //返回替换字符串。
}
function ownProperty()
{
var s = new String("JScript");
alert(s.hasOwnProperty("split"));
alert("string prototype:"+String.prototype);
alert(String.prototype.hasOwnProperty("split"));
}
function RegExpTest(){
var ver = Number(ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion())
alert(ver);
if (ver >= 5.5){
var src = "The rain in Spain falls mainly in the plain.";
var re = /\w+/g;
var arr;
while ((arr = re.exec(src)) != null)
alert(arr.index + "-" + arr.lastIndex + "\t" + arr);
}
else{
alert("You need a newer version of JScript for this to work");
}
}
//input的属性
function inputDemo(){
var s;
var re = new RegExp("d(b+)(d)","ig");
var str = "cdbBdbsbdbdz";
var arr = re.exec(str);
s = "The string used for the match was " + RegExp.input;
alert(s);
return(s);
}
//length Array
function LengthDemo(){
var a;
a = new Array(0,1,2,3,4);
alert(a.length);
}
//length Function
function ArgTest(a, b){
var i, s = "The ArgTest function expected ";
var numargs = ArgTest.arguments.length;
var expargs = ArgTest.length;
if (expargs < 2)
s += expargs + " argument. ";
else
s += expargs + " arguments. ";
if (numargs < 2)
s += numargs + " was passed.";
else
s += numargs + " were passed.";
alert(s);
}
//test prototype
function array_max( ){
var i, max = this[0];
for (i = 1; i < this.length; i++)
{
if (max < this[i])
max = this[i];
}
return max;
}
Array.prototype.max = array_max;
var x = new Array(1, 2, 3, 4, 5, 6);
var y = x.max( );
</script>
</head>
<body>
<button οnclick="result()">
测试参数
</button><br/>
<button οnclick="callLevel()">
测试调用的函数
</button><br/>
<button οnclick="consta()">
测试构造器
</button><br/>
<button οnclick="newVar()">
测试显示函数和隐式函数,以及E的值
</button><br/>
<button οnclick="RegExpPropDemo('m')">
测试global
</button><br/>
<button οnclick="ownProperty()">
测试Property和ownProperty
</button><br/>
<button οnclick="RegExpTest()">
测试index和lastIndex
</button><br/>
<button οnclick="inputDemo()">
测试input
</button><br/>
<button οnclick="LengthDemo()">
测试length
</button><br/>
<button οnclick="ArgTest(1,2)">
测试length of Function
</button><br/>
</body>
<html>
<head>
<script type="text/javascript">
function ArgTest(){
var i, s, numargs = arguments.length;
s = numargs;
if (numargs < 2)
s += " argument was passed to ArgTest. It was ";
else
s += " arguments were passed to ArgTest. They were " ;
for (i = 0; i < numargs; i++)
{
s += arguments[i] + " ";
}
return(s);
}
//测试函数传入的参数的个数
function result()
{
var re = ArgTest(1,2);
alert('Arguments result:' + re);
}
//测试调用的函数体
function callLevel()
{
var callLe = result.caller;
alert(callLevel);
}
//两个方法名相同的方法,回自动适配写在后面的一个
function consta()
{
var con = new String("11").constructor;
alert("con:"+con);
}
function consta()
{
var con = new String("11").constructor;
alert("consta:"+con);
}
//测试E,以及显示函数和隐式函数
var aa = function newVar()
{
alert(Math.E);
}
//测试global属性
function RegExpPropDemo(flag){
if (flag.match(/[^gim]/)) //检查标志的有效性。
return("Flag specified is not valid");
var r, re, s //声明变量。
var ss = "The man hit the ball with the bat.\n";
ss += "while the fielder caught the ball with the glove.";
re = new RegExp("the",flag); //指定要查找的样式。
alert("re"+re);
r = ss.replace(re, "a"); //用 "a" 替换 "the"。
s = "Regular Expression property values:\n\n"
s += "global ignoreCase multiline\n"
if (re.global) //测试 global 标志。
s += " True ";
else
s += "False ";
if (re.ignoreCase) //测试 ignoreCase 标志。
s += " True ";
else
s += "False ";
if (re.multiline) //测试 multiline 标志。
s += " True ";
else
s += " False ";
s += "\n\nThe resulting string is:\n\n" + r;
alert(s);
return(s); //返回替换字符串。
}
function ownProperty()
{
var s = new String("JScript");
alert(s.hasOwnProperty("split"));
alert("string prototype:"+String.prototype);
alert(String.prototype.hasOwnProperty("split"));
}
function RegExpTest(){
var ver = Number(ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion())
alert(ver);
if (ver >= 5.5){
var src = "The rain in Spain falls mainly in the plain.";
var re = /\w+/g;
var arr;
while ((arr = re.exec(src)) != null)
alert(arr.index + "-" + arr.lastIndex + "\t" + arr);
}
else{
alert("You need a newer version of JScript for this to work");
}
}
//input的属性
function inputDemo(){
var s;
var re = new RegExp("d(b+)(d)","ig");
var str = "cdbBdbsbdbdz";
var arr = re.exec(str);
s = "The string used for the match was " + RegExp.input;
alert(s);
return(s);
}
//length Array
function LengthDemo(){
var a;
a = new Array(0,1,2,3,4);
alert(a.length);
}
//length Function
function ArgTest(a, b){
var i, s = "The ArgTest function expected ";
var numargs = ArgTest.arguments.length;
var expargs = ArgTest.length;
if (expargs < 2)
s += expargs + " argument. ";
else
s += expargs + " arguments. ";
if (numargs < 2)
s += numargs + " was passed.";
else
s += numargs + " were passed.";
alert(s);
}
//test prototype
function array_max( ){
var i, max = this[0];
for (i = 1; i < this.length; i++)
{
if (max < this[i])
max = this[i];
}
return max;
}
Array.prototype.max = array_max;
var x = new Array(1, 2, 3, 4, 5, 6);
var y = x.max( );
</script>
</head>
<body>
<button οnclick="result()">
测试参数
</button><br/>
<button οnclick="callLevel()">
测试调用的函数
</button><br/>
<button οnclick="consta()">
测试构造器
</button><br/>
<button οnclick="newVar()">
测试显示函数和隐式函数,以及E的值
</button><br/>
<button οnclick="RegExpPropDemo('m')">
测试global
</button><br/>
<button οnclick="ownProperty()">
测试Property和ownProperty
</button><br/>
<button οnclick="RegExpTest()">
测试index和lastIndex
</button><br/>
<button οnclick="inputDemo()">
测试input
</button><br/>
<button οnclick="LengthDemo()">
测试length
</button><br/>
<button οnclick="ArgTest(1,2)">
测试length of Function
</button><br/>
</body>
<html>