number对象,bom对象

时间:2024-01-19 23:50:45

number对象

新创建一个number的对象,toFixed是精确到位数

    var num =new Number('123.1231');
console.log(num.toFixed(1));

小技巧:可以获取函数传入了多少个参数。

    var abc =function ()
{
if (arguments.length===2)
{
alert('have 2 value');
}
else if (arguments.length===3)
{
alert('have 3 value');
}
}

Function可以這样用,最后一个参数是返回值

    var abc1=new Function ('a','b','c','alert(a+b+c);');
abc1(2,3,4);

  

bom对象

小功能:屏幕自动往下动,

      var i=0;
 setInterval(function()
{
document.body.scrollTop=i++;
}, 100);

页面向前,向后,

console.log(history.length);
history.back();
history.forward();
history.go(0);

小功能:延迟3000毫秒返回上一个网页

       window.onload=function()
{
setTimeout(function(){
history.go(-1);
}, 3000)
}

location

   location.hash;  //获取当前苗点
location.href; //当前的url,這是属性
location.hostname; //当前主机名字
location.pathname; //主机名后面的名字
location.protocal; //返回传输协议
location.search; //返回带问号的参数值
location.assign('https://baidu.com'); //当前的url,这是方法
location.replace('http://baidu.com');//加载其他网页
location.reload(); //重新载入当前的网页

小技巧:获取get方法传送的参数

alert(window.location.href.substr(window.location.href.indexOf("=")+1))