做題遇到的問題2

1.哪一個是javascript中array的正確寫法?

A var txt = new Array("tim","kim","jim")
B var txt = new Array="tim","kim","jim"
C var txt = new Array:1=("tim")2=("kim")3=("jim")
D var txt = new Array(1:"tim",2:"kim",3:"jim")

正確答案: A
[D選項是創建對象的語法,而不是數組]

創建 Array 對象的語法
new Array();
new Array(size);
new Array(element0, element1, ..., elementn);
----------------------
var arr=[1,2,3];     
var arr=new Array(1,2,3);     
var arr=new Array(12);如果只有一個數,代表數組的length是12個
var arr=new Array(0);     清空數組

2.如果不給cookie設置過期時間會怎麼樣?
在瀏覽器會話結束時過期
3.當點擊id爲b的div時,控制檯輸出的內容是:

假設DOM結構爲:
<div id="a">
	<div id="b"></div>
</div>
JS代碼爲:
document.getElementById('a')
	.addEventListener('click', e => {console.log(1)});
document.getElementById('b')
	.addEventListener('click', e => {e.preventDefault();console.log(2)});
當點擊id爲b的div時,控制檯輸出的內容是:
2
1
e.preventDefault() 是用來阻止默認事件的,不是阻止事件冒泡. 事件冒泡應該是 **e.stopPropagation()**

4.以下js表達式返回值

	console.log(1==true);//true
    console.log(""==false);//true
    console.log(false==null);//false
    console.log(null==undefined);//true
    
    console.log(![]);//false
    console.log(1/0);//Infinity
    console.log(isNaN(1/0));//false
    

undefined和null與任何有意義的值比較返回的都是false,但是null與undefined之間互相比較"=="是true, "==="是false

	console.log(null == false);//false
    console.log(null == true);//false
    console.log(undefined == false);//false
    console.log(undefined == true);//false
    console.log(undefined == null);//true
    console.log(undefined == undefined);//true
    console.log(null == null);//true
    console.log(undefined === null);//false

5.angularjs1中指令中的compile參數是在什麼時候運行的?
答案:在生成DOM後掃描並生成
解析:
C. angularJS肯定是在DOM節點樹生成後開始管理節點的,生成後尋找ng-app標記,然後其下屬所有節點均由ng來管理。
使用compile可以改變原始的dom,在ng創建原始dom實例以及創建scope實例之前. ng-repeat就是一個最好的例子,它就在是compile函數階段改變原始的dom生成多個原始dom節點,然後每個又生成element實例.

爲了解決AngularJS性能問題,編譯階段應分爲兩個階段
1,compile (綁定DOM)   
2,link(數據綁定)。

所以綁定dom應該在dom生成以後綁定的。
不過也可能是動態生成的

原生 js 操作數組的方法:A B D E F G
A splice
B shift
C resort
D sort
E pop
F push
G unshift

解析:
Array 對象方法
方法 concat() 連接兩個或更多的數組,並返回結果。
join() 把數組的所有元素放入一個字符串。元素通過指定的分隔符進行分隔。
pop() 刪除並返回數組的最後一個元素
push() 向數組的末尾添加一個或更多元素,並返回新的長度。
reverse() 顛倒數組中元素的順序。
shift() 刪除並返回數組的第一個元素 slice() 從某個已有的數組返回選定的元素
sort() 對數組的元素進行排序
splice() 刪除元素,並向數組添加新元素。
toSource() 返回該對象的源代碼。
toString() 把數組轉換爲字符串,並返回結果。 toLocaleString() 把數組轉換爲本地數組,並返回結果。 unshift() 向數組的開頭添加一個或更多元素,並返回新的長度。
valueOf() 返回數組對象的原始值

6.頁面有一個按鈕button id爲 button1,通過原生的js如何禁用?(IE 考慮IE 8.0以上版本)

1.document.getElementById("button1").disabled = true;

2.document.getElementById("button1")
.setAttribute(“disabled”,”true”);

①disabled和readOnly都是表單的公有屬性, readOnly是隻讀, disabled是禁用。這裏問的是禁用,所以是disabled。
②還有就是題目中的 readOnly寫成了 readolny
③小知識點:setArrtibute在ie7以前是不能通過style和class設置屬性的

7.以下哪些HTML元素可以獲得焦點?
在這裏插入圖片描述

“rsgesg”

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章