標籤:java 使用 os io ar 問題 cti javascript
1.<noscript>
現代瀏覽器都對JavaScript進行了支援,一般是在使用者的瀏覽器禁用了指令碼的情況下才會顯示<noscript>的內容。
包含在<noscript>元素中的內容只有在下列情況下才會顯示出來:
- 瀏覽器不支援指令碼;
- 瀏覽器支援指令碼,但指令碼被禁用。
2. Object 類型
建立 Object 類型有兩種。一種是使用 new 運算子,一種是字面量標記法。
兩種屬性輸出方式
alert(box.age);
alert(box[‘age‘]);
3.Array 類型
建立 Array 類型有兩種方式:第一種是 new 運算子,第二種是字面量。
a. 使用 new 關鍵字建立數組
var box = new Array(); // 建立了一個數組
var box = new Array(10); // 建立一個包含 10 個元素的數組
var box = new Array(‘ 李炎恢 ‘,28,‘ 教師 ‘,‘ 鹽城 ‘); // 建立一個數組並分配好了元素
b 使用字面量方式建立數組
var box = []; // 建立一個空的數組
var box = [‘ 李炎恢 ‘,28,‘ 教師 ‘,‘ 鹽城 ‘]; // 建立包含元素的數組
var box = [1,2,]; // 禁止這麼做, IE 會識別 3 個元素
var box = [,,,,,]; // 同樣, IE 的會有識別問題
預設情況下,數組字串都會以逗號隔開。如果使用 join() 方法,則可以
符來構建這個字串。
var box = [‘ 李炎恢 ‘, 28, ‘ 電腦編程 ‘];
alert(box.join(‘|‘)); // 李炎恢 |28| 電腦編程
push() 方法可以接收任意數量的參數 , 把它們逐個添加到數組的末尾 , 並
的長度。而 pop() 方法則從數組末尾移除最後一個元素,減少數組的 length
除的元素。
var box = [‘ 李炎恢 ‘, 28, ‘ 電腦編程 ‘]; // 字面量聲明
alert(box.push(‘ 鹽城 ‘)); // 數組末尾添加一個元素 ,
alert(box); // 查看數組
box.pop(); // 移除數組末尾元素 , 並返
alert(box); // 查看元素
alert(box.unshift(‘ ‘,‘ ‘)); //
alert(box.shift()); // 移除數組開頭元素 , 並返回移除的元素
數組排序:sort()需要重寫,原來的是按字串排序
var box = [0,1,5,10,15]; // 驗證數字字串,和數字
alert(box);
alert(box.sort(compare)); // 傳參
function compare(value1,value2) {
if (value1 < value2) {
return -1;
} else if (value1 > value2) {
return 1;
} else {
return 0;
}
}