使用示例:
var oNumberObject = new Number(68);
1.toFixed() 方法toFixed() 方法返回的是具有指定位数小数的数字的字符串表示。与Math对象的round()方法功能相似。例如:
var oNumberObject = new Number(68);
alert(oNumberObject.toFixed(2)); //输出 "68.00"
2.toExponential() 方法与格式化数字相关的另一个方法是 toExponential(),它返回的是用科学计数法表示的数字的字符串形式。
var oNumberObject = new Number(68);
alert(oNumberObject.toExponential(1)); //输出 "6.8e+1"
3.toPrecision() 方法toPrecision() 方法根据最有意义的形式来返回数字的预定形式或指数形式。它有一个参数,即用于表示数的数字总数(不包括指数)。例如,
var oNumberObject = new Number(68);
alert(oNumberObject.toPrecision(1)); //输出 "7e+1"
公共方法之addBehavior:为对象绑定行为语法:iID = object.addBehavior(sUrl)
示例:
<SCRIPT LANGUAGE="JScript" >
var collBehaviorID = new Array();
var collLI = new Array ();
var countLI = 0;
function attachBehavior()
{
collLI = document.all.tags ("LI");
countLI = collLI.length;
for (i=0; i < countLI; i++)
{
var iID = collLI[i].addBehavior ("hilite.htc");
if (iID)
collBehaviorID[i] = iID;
}
}
</SCRIPT >
:
//Click <A HREF="javascript:attachBehavior()" >here</A >
//to add a highlighting effect as you hover over each item below.
Hilite.htc代码如下:
<PUBLIC:COMPONENT >
<PUBLIC:ATTACH EVENT="ondetach" ONEVENT="cleanup()" / >
<SCRIPT LANGUAGE="JScript" >
var normalColor;
attachEvent ('onmouseover', Hilite);
attachEvent ('onmouseout', Restore);
function cleanup()
{
window.status = 'ondetach event fired';
detachEvent ('onmouseover', Hilite);
detachEvent ('onmouseout', Restore);
}
function Hilite()
{
if (event.srcElement == element)
{
normalColor = style.color;
runtimeStyle.color = "red";
runtimeStyle.cursor = "hand";
}
}
function Restore()
{
if (event.srcElement == element)
{
runtimeStyle.color = normalColor;
runtimeStyle.cursor = "";
}
}
</SCRIPT >
</PUBLIC:COMPONENT >