javascript學(xué)習(xí)筆記(八) js內(nèi)置對象
更新時間:2012年06月19日 23:11:39 作者:
javascript學(xué)習(xí)筆記之js內(nèi)置對象,需要的朋友可以參考下
1.URI方法
encodeURI()和encodeURIComponent()對URI進行編碼
encodeURI()不會對本身屬于URI的特殊字符進行編碼,如冒號,正斜杠,問好,井字等
encodeURIComponent()會對任何非標(biāo)準(zhǔn)字符進行編碼
2.eval() 方法:解釋參數(shù)中的代碼字符串
var msg = "hello world";
eval("alert(msg)"); //"hello world"
3.Math 對象
Math.E 數(shù)學(xué)中的e的值
Math.PI π的值
Math.SQRT2 2的平方根
Math.abs(num) num的絕對值
Math.exp(num) e的num次冪
Math.log(num) num的自然對數(shù)
Math.pow(num,n) num的n次冪
Math.sqrt(num) num的平方根
Math.acos(x) x的反余弦值
Math.asin(x) x的反正弦值
Math.atan(x) x的反正切值
Math.atan2(y,x) y/x的反正切值
Math.cos(x) x的余弦值
Math.sin(x) x的正弦值
Math.tan(x) x的正切值
4.min()和max()方法
var max = Math.max(3,45,67,32);
alert(max); //67
var min = Math.min(2,46,74);
alert(min); //2
5.小數(shù)舍入到整數(shù)方法
Math.ceil() 向上舍入
Math.floor() 向下舍入
Math.round() 四舍五入
alert(Math.ceil(25.1)); //26
alert(Math.ceil(25.5)); //26
alert(Math.ceil(25.9)); //26
alert(Math.round(25.1)); //25
alert(Math.round(25.5)); //26
alert(Math.round(25.9)); //26
alert(Math.floor(25.1)); //25
alert(Math.floor(25.5)); //25
alert(Math.floor(25.9)); //25
6. random() 方法 返回 介于 0~1 的一個隨機數(shù),不包括0和1
在某一范圍內(nèi)取一個隨機數(shù)公式:
隨機數(shù) = Math.floor(Math.random * 總數(shù) + 第一個值) // 總數(shù)=第二個值 - 第一個值
//取范圍內(nèi)隨機數(shù)函數(shù)
function selectFrom(lowerValue,upperValue) {
var count = upperValue - lowerValue + 1;
return Math.floor(Math.random() * count +lowerValue);
}
var num = selectFrom(2,10);
alert(num); //介于2~10之間的數(shù)(包括2和10)
encodeURI()和encodeURIComponent()對URI進行編碼
encodeURI()不會對本身屬于URI的特殊字符進行編碼,如冒號,正斜杠,問好,井字等
encodeURIComponent()會對任何非標(biāo)準(zhǔn)字符進行編碼
2.eval() 方法:解釋參數(shù)中的代碼字符串
復(fù)制代碼 代碼如下:
var msg = "hello world";
eval("alert(msg)"); //"hello world"
3.Math 對象
Math.E 數(shù)學(xué)中的e的值
Math.PI π的值
Math.SQRT2 2的平方根
Math.abs(num) num的絕對值
Math.exp(num) e的num次冪
Math.log(num) num的自然對數(shù)
Math.pow(num,n) num的n次冪
Math.sqrt(num) num的平方根
Math.acos(x) x的反余弦值
Math.asin(x) x的反正弦值
Math.atan(x) x的反正切值
Math.atan2(y,x) y/x的反正切值
Math.cos(x) x的余弦值
Math.sin(x) x的正弦值
Math.tan(x) x的正切值
4.min()和max()方法
復(fù)制代碼 代碼如下:
var max = Math.max(3,45,67,32);
alert(max); //67
var min = Math.min(2,46,74);
alert(min); //2
5.小數(shù)舍入到整數(shù)方法
Math.ceil() 向上舍入
Math.floor() 向下舍入
Math.round() 四舍五入
復(fù)制代碼 代碼如下:
alert(Math.ceil(25.1)); //26
alert(Math.ceil(25.5)); //26
alert(Math.ceil(25.9)); //26
alert(Math.round(25.1)); //25
alert(Math.round(25.5)); //26
alert(Math.round(25.9)); //26
alert(Math.floor(25.1)); //25
alert(Math.floor(25.5)); //25
alert(Math.floor(25.9)); //25
6. random() 方法 返回 介于 0~1 的一個隨機數(shù),不包括0和1
在某一范圍內(nèi)取一個隨機數(shù)公式:
隨機數(shù) = Math.floor(Math.random * 總數(shù) + 第一個值) // 總數(shù)=第二個值 - 第一個值
復(fù)制代碼 代碼如下:
//取范圍內(nèi)隨機數(shù)函數(shù)
function selectFrom(lowerValue,upperValue) {
var count = upperValue - lowerValue + 1;
return Math.floor(Math.random() * count +lowerValue);
}
var num = selectFrom(2,10);
alert(num); //介于2~10之間的數(shù)(包括2和10)
您可能感興趣的文章:
- 淺談JavaScript的內(nèi)置對象和瀏覽器對象
- 淺析JSP的9大內(nèi)置對象和4大作用域?qū)ο?/a>
- Javascript中prototype屬性實現(xiàn)給內(nèi)置對象添加新的方法
- javascript內(nèi)置對象arguments詳解
- JSP內(nèi)置對象:Request和Response的簡單介紹及使用
- jsp內(nèi)置對象及方法詳細(xì)介紹
- javascript 基礎(chǔ)篇3 類,回調(diào)函數(shù),內(nèi)置對象,事件處理
- js內(nèi)置對象 學(xué)習(xí)筆記
- JavaScript 內(nèi)置對象屬性及方法集合
- JavaScript學(xué)習(xí)筆記--常用的互動方法
相關(guān)文章
客戶端腳本中常常出現(xiàn)的一些問題和調(diào)試技巧
客戶端腳本中常常出現(xiàn)的一些問題和調(diào)試技巧...2007-01-01js基礎(chǔ)知識(公有方法、私有方法、特權(quán)方法)
這篇文章主要介紹了js基礎(chǔ)知識,包括公有方法、私有方法,以及特權(quán)方法的使用介紹,感興趣的小伙伴們可以參考一下2015-11-11「中高級前端面試」JavaScript手寫代碼無敵秘籍(推薦)
這篇文章主要介紹了JavaScript手寫代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04