標籤:des style io ar os 使用 java sp strong
JavaScript provides several built-in(內建的) datatypes. In addition to those, this page documents virtual types(虛類) like Selectors, enhanced pseudo-types(偽類) like Events and all and everything you wanted to know about Functions.
jQuery除了包含原生JS中的內建資料類型(built-in datatype),還包括一些擴充的資料類型(virtual types),如Selectors、Events等。
一、Anything
在jQuery文檔中任何虛擬類型(virtual type)的使用表明可以使用任何類型或應該被期望。
二、String
A string in JavaScript is an immutable(不變的) object that contains none, one or many characters.
(1)var typeOfStr = typeof "hello world";//typeOfStr為“string"
(2)內建方法(Built-in Methods):
"hello".charAt( 0 ) // "h""hello".toUpperCase() // "HELLO""Hello".toLowerCase() // "hello""hello".replace( /e|o/g, "x" ) // "hxllx""1,2,3".split( "," ) // [ "1", "2", "3" ]
(3)length屬性:返回字元長度,比如"hello".length返回5
(4)String轉換為Boolean:一個Null 字元串("")預設為false,而一個非Null 字元串為true(比如"hello")。
三、htmlString
在jQuery文檔用於表示一個或多個DOM元素的String被指定為htmlString,通常建立和插入文檔中。當作為jQuery()函數的一個參數傳遞時,該字串如果是以<tag>開始和解析,直到最後>字元。樣本如下:
$( "<b>hello</b>" ).appendTo( "body" ); // <body><b>hello</b></body>$( "<b>hello</b>bye" ).appendTo( "body" ); // <body><b>hello</b></body>$( "bye<b>hello</b>" ).appendTo( "body" ); // 語法錯誤(Syntax error), unrecognized expression: bye<b>hello</b>$( $.parseHTML( "bye<b>hello</b>" ) ).appendTo( "body" ); // <body>bye<b>hello</b></body>$( "<b>hello</b>wait<b>bye</b>" ).appendTo( "body" ); // <b>hello</b>wait<b>bye</b>:
四、Number
在原生JavaScript中,Number是64位格式IEEE 754雙精確度(double-precision)值。就像字串是不可變的。所有常見操作符等同於在於c語言中可以應用於數字(+, -, *, /, % , =, +=, -=, * =, /=, ++, --)。
(1)String轉換為Boolean:If a number is zero, it defaults to false.
(2)Math,數學對象:
Math.PI // 3.141592653589793
Math.cos(Math.PI) // -1
(3)Parsing Numbers,轉換為數字:parseInt和parseFloat方法
parseInt( "123" ) = 123 // (implicit decimal(十進位))parseInt( "010" ) = 8 // (implicit octal(八進位))parseInt( "0xCAFE" ) = 51966 // (implicit hexadecimal(十六進位))parseInt( "010", 10 ) = 10 // (explicit decimal(十進位))parseInt( "11", 2 ) = 3 // (explicit binary(二進位))parseFloat( "10.10" ) = 10.1
(4)Numbers to Strings,數字轉換為字串
[1]當將Number粘到(append)字串後的時候,將得到字串。
"" + 1 + 2; // "12" "" + (1 + 2); // "3" "" + 0.0000001; // "1e-7" parseInt( 0.0000001 ); // 1 (!)
[2]或者用強制類型轉換:
String(1) + String(2); //"12" String(1 + 2); //"3"
(5)NaN and Infinity(Both NaN and Infinity are of type "number"):
如果對一個非數字字串調用parseInt方法,將返回NaN(Not a Number),isNaN常用來檢測一個變數是否數字類型,如下:
parseInt( "hello", 10 ) // NaN isNaN( parseInt("hello", 10) ) // true
Infinity表示數值無窮大或無窮小,比如 1 / 0 // Infinity。
另外 NaN==NaN 返回false,但是 Infinity==Infinity 返回true。
(6)Integer 和 Float:分為表示整型和浮點型,都是數字類型。
五、Boolean:布爾類型,true或者false。
六、Object對象
JavaScript中的一切皆對象。對一個對象進行typeof運算返回 "object"。
var x = {}; var y = { name: "Pete", age: 15 };
對於上面的y對象,可以採用圓點擷取屬性值,比如y.name返回"Pete",y.age返回15
Jquery Types 小結