亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

javascript parseInt與Number函數(shù)的區(qū)別

 更新時間:2010年01月21日 22:36:11   作者:  
在js中,如果你使用parseInt("08"),一般都會認(rèn)為會返回8,然而實際上返回了0.但是用Number("08")返回的才是8.
但是parseInt("08", 10)是可以返回8的。

為搞清楚兩者的區(qū)別,

參考了別人寫的parseInt&Number的區(qū)別:

parseInt
Parses a string argument and returns an integer of the specified radix or base.
核心函數(shù)
實現(xiàn)版本 Navigator 2.0: If the first character of the string specified in parseInt(string) cannot be converted to a number, returns "NaN" on Solaris and Irix and 0 on all other platforms.Navigator 3.0, LiveWire 2.0: Returns "NaN" on all platforms if the first character of the string specified in parseInt(string) cannot be converted to a number.



語法
parseInt(string,radix)
參數(shù)
string A string that represents the value you want to parse.
radix (Optional) An integer that represents the radix of the return value.



描述
The parseInt function is a built-in JavaScript function.
The parseInt function parses its first argument, a string, and attempts to return an integer of the specified radix (base). For example, a radix of 10 indicates to convert to a decimal number, 8 octal, 16 hexadecimal, and so on. For radixes above 10, the letters of the alphabet indicate numerals greater than 9. For example, for hexadecimal numbers (base 16), A through F are used.

If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values.

If the radix is not specified or is specified as 0, JavaScript assumes the following:



If the input string begins with "0x", the radix is 16 (hexadecimal).

If the input string begins with "0", the radix is eight (octal).

If the input string begins with any other value, the radix is 10 (decimal).
If the first character cannot be converted to a number, parseInt returns "NaN".
For arithmetic purposes, the "NaN" value is not a number in any radix. You can call the isNaN function to determine if the result of parseInt is "NaN". If "NaN" is passed on to arithmetic operations, the operation results will also be "NaN".


示例
The following示例 all return 15:
parseInt("F", 16)
parseInt("17", 8)
parseInt("15", 10)
parseInt(15.99, 10)
parseInt("FXX123", 16)
parseInt("1111", 2)
parseInt("15*3", 10) The following示例 all return "NaN":

parseInt("Hello", 8)
parseInt("0x7", 10)
parseInt("FFF", 10) Even though the radix is specified differently, the following示例 all return 17 because the input string begins with "0x".

parseInt("0x11", 16)
parseInt("0x11", 0)
parseInt("0x11")
-----------------------------------------------
-----------------------------------------------
將指定對象轉(zhuǎn)換為數(shù)字。
核心函數(shù)
實現(xiàn)版本 Navigator 4.0, Netscape Server 3.0

語法
Number(obj)
參數(shù)
obj 一個對象。



描述
如果對象是 Date 類型的對象,Number 將返回自格林威治標(biāo)準(zhǔn)時間 1970 年 1 月 1 日起已經(jīng)經(jīng)過的毫秒數(shù),在此日期之后的是正數(shù),之前的是負(fù)數(shù)。
如果 obj 是一個沒有數(shù)字格式的字符串,Number 將返回 NaN。


示例
下面的例子將把 Date 對象轉(zhuǎn)換為數(shù)值型值:
<SCRIPT>
d = new Date ("December 17, 1995 03:24:00");
document.write (Number(d) + "<BR>");

相關(guān)文章

  • Swiper實現(xiàn)輪播圖效果

    Swiper實現(xiàn)輪播圖效果

    這篇文章主要為大家詳細(xì)介紹了Swiper實現(xiàn)輪播圖效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • JavaScript遞歸操作實例淺析

    JavaScript遞歸操作實例淺析

    這篇文章主要介紹了JavaScript遞歸操作,由一個階乘問題開始分析了遞歸操作的原理、實現(xiàn)方法與相關(guān)注意事項,需要的朋友可以參考下
    2016-10-10
  • 小程序?qū)崿F(xiàn)授權(quán)登陸的解決方案

    小程序?qū)崿F(xiàn)授權(quán)登陸的解決方案

    這篇文章主要介紹了小程序?qū)崿F(xiàn)授權(quán)登陸的解決方案,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-12-12
  • JS實現(xiàn)在線統(tǒng)計一個頁面內(nèi)鼠標(biāo)點擊次數(shù)的方法

    JS實現(xiàn)在線統(tǒng)計一個頁面內(nèi)鼠標(biāo)點擊次數(shù)的方法

    這篇文章主要介紹了JS實現(xiàn)在線統(tǒng)計一個頁面內(nèi)鼠標(biāo)點擊次數(shù)的方法,實例分析了javascript操作Cookie實現(xiàn)計數(shù)的技巧,需要的朋友可以參考下
    2015-02-02
  • js 自定義的聯(lián)動下拉框

    js 自定義的聯(lián)動下拉框

    一直都嫌下拉框這個html控件難看,之前弄了個<div><ul><li></li></ul></div>版的下拉框.
    2010-02-02
  • JS+css 圖片自動縮放自適應(yīng)大小

    JS+css 圖片自動縮放自適應(yīng)大小

    編輯器上傳的圖片太大了,把FF和IE撐的走形,所以希望圖片在某些頁面里要有固定大小,如果需要某個范圍,用getElementByname來設(shè)定,也是一個道理:
    2013-08-08
  • JS中some和every的區(qū)別和用法詳解

    JS中some和every的區(qū)別和用法詳解

    every?和?some?都是數(shù)組迭代方法,都可以遍歷數(shù)組,這篇文章主要介紹了JS中some和every的區(qū)別和用法,需要的朋友可以參考下
    2023-05-05
  • 公眾號SVG動畫交互實戰(zhàn)代碼

    公眾號SVG動畫交互實戰(zhàn)代碼

    這篇文章主要介紹了公眾號SVG動畫交互實戰(zhàn)代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • 如何解決java.lang.NumberFormatException: null異常

    如何解決java.lang.NumberFormatException: null異常

    這篇文章主要介紹了如何解決java.lang.NumberFormatException: null異常問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • js實現(xiàn)搜索框關(guān)鍵字智能匹配代碼

    js實現(xiàn)搜索框關(guān)鍵字智能匹配代碼

    這篇文章主要為大家分享了js實現(xiàn)搜索框關(guān)鍵字智能匹配代碼,感興趣的朋友可以參考一下
    2016-01-01

最新評論