Inspirational to get Ali's question bank out! The main purpose, of course, is to know what other knowledge points are lacking and inadequate.
1.
(1) The onclick event of this element, which of course refers to this element.
(2) window
(3) window Neither of these methods has passed element to dosomething, so this is the default point to Window
2.
1Array.prototype.sorting =function(FN) {2 varT;3 if(!fn) {4fn =function(A, b) {5 returnA-b;6 }7 }8 for(vari = 0;i< This. length;i++){9 for(varj=i+1;j< This. length;j++){Ten if(FN ( This[I], This[j]) >0){ Onet = This[j]; A This[j] = This[i]; - This[I] =T; - } the } - } - } - vararr = [4,85,1,2,37,88,6]; + arr.sorting (); -Console.log (arr);
The final output is 1, 2, 4, 6, 37, 85, 88 I think there is nothing to say, there are many algorithms, if you do not know what sort is, please Baidu
3.
A, add components of the event monitoring function
B, advantages: Solve the IE in the point to the window problem, you can add event monitoring
Disadvantage: Browser compatibility considerations are not comprehensive, IE9 and later versions have added the AddEventListener method, through the document.all if else if the statement after the possible execution
In addition, the sixth line addlistener with the global variables, the correct should be added Var
C, apply is to change the point of this, let this point to the incoming El object (as for the difference between apply and call, please see my other blog http://www.cnblogs.com/jianjianwoshi/p/4369869.html)
4.
functionTorgb (str) {varReg =/^#[0-9a-za-z]{3}$/; if(str = = "Invalid")){ return"Invalid"; }Else if(Reg.test (str)) {returnstr; }Else{ vararr =NewArray (); for(vari=1;i<str.length;i+=2){ varGG = Str.substr (i,2); varCC = parseint (gg,16); Arr.push (CC); } return"RGB (" +arr[0]+ "," +arr[1]+ "," +arr[2]+ ")"}} alert (Torgb ("#0ff"));
The writing is very simple, the judging condition is not perfect, have time to optimize again
5.
1 varobj=function(msg) {2 This. msg =msg;3that = This;4 This. Shout =function(){5Alert This. msg);6 }7 This. Waitandshout =function(){8SetTimeout ("That.shout ()", 5000);9 }Ten } One vart =NewObj (); AT.waitandshout ();
Said it couldn't be done, take a good look at the third line is the key
6.
<Div> <ahref=""title= "Description of the product, introduction"> <imgsrc=""title= "Lenovo IdeaPad U130"alt= "Lenovo IdeaPad U130 product Map"/> <span>Lenovo IdeaPad U130</span> <span>Red Extreme High cost performance</span> <Strong>¥8888.00</Strong> </a> </Div>
7.
1 var obj = document.body; 2 var odiv = document.createelement ("div"); 3 odiv.setattribute ("id", "example"); 4 Obj.appendchild (odiv); 5 var op = document.createelement ("P"); 6 Op.setattribute ("Class", "slogan"); 7 odiv.appendchild (OP); 8 console.log (obj);
This simple, no, no, no.
8.
Well, I'm just going to write a simple regular, not a complicated one, that's the point, it's going to take some time to learn.
Here to borrow the answers of netizens
var reg = /^[a-za-z0-9_-][email protected][a-za-z0-9_-]+ (\.[ a-za-z0-9_-]+) +$/;
9.
p{
*color: #000000;//ie7
_color: #ff0000;//ie6
Color: #00ff00;
}
10.
varText = document.getElementsByTagName ("input") [0]; Text.addeventlistener ("Focus", Ofocus,false); Text.addeventlistener ("Blur", Oblur,false); functionOfocus () {if( This. value== "Please enter content"){ This. Value = ""; Text.style.color= "#000"; } } functionOblur () {if( This. Value = = ""){ This. Value = "Please enter content"; Text.style.color= "#ccc"; } }
Initially the default color is gray
11.
12.
Array.prototype.repeat =function(){ vartt =NewArray (); for(vari = 0;i< This. length;i++){ if(Tt.indexof ( This[i]) = =-1) {Tt.push ( This[i]); } } returntt; } vararr = [0,0,1,1,2,8,8,2,45,656,4,45,2,3,3]; Alert (Arr.repeat ());
I feel this is the simplest idea, and of course there are many ways to do it.
13.
If you do not know CSS3 flexible layout, quickly go to Baidu Flex
*{margin:0px;padding:0px; }. Div{Display:-moz-box;Display:-webkit-box;width:400px;Height:40px;Background-color:Green; }. BC{Background-color: White;margin:10px; }. WD{width:200px; }
A day to accumulate a bit of Ali pen questions