1.1 Review 1. Button not available disabled = "Disabled" | | True 2. SetTimeout executes only once setinterval executes many times 3. Recursive invocation: The function calls itself function recursive call does not advocate using the function name and like to use is Arguments.callee return is executing the function itself 4. logical operators with && or | | Non -!! > && > | | 5.2&&00 1&&80&&3 0 1| | 0 6. Convert to character var num = 12345; num+ "" String (num); Num.tostring (); 10 binary num.tostring (2) binary 7. Returns the character charAt (index number) based on the character position var txt = "ABCDE"; Txt.charat (3); D charCodeAt (3) Unicode encoding 97 1001.2 returns position according to character with CharAt () opposite to the position 1.2.1 returns the position of the first character before IndexOf ("character"), which is the number starting from the front (the number from the left), and only the first one, and then return to the position of the modifier, the index number is starting from 0. The value returned is a number. var txt = "abcdef"; The result of alert (Txt.indexof ("D")) is 3 if the character is not found returns-1 1.2.2 returns the position of the first character after LastIndexOf (parameter: index string) starting from the back number of the same as Var t XT = "ABCdef"; Txt.lastindexof ("D"); 3 The value returned, or the index number of the number to start from the left. 1.3 URL code We know a URL of their own URLs, different pages also have their own ID URL, we often do some, put the URL into the background. But do not know the background to deal with such as the new line Ah, such as special symbols? var url = "Http://www.itast.cn?name=cz" So we're going to encode it and then upload it back to the background. The encodeURIComponent () function encodes a string as a URI component decodeURIComponent () function to decode a string as a URI component var url = "Http://www.itcast.cn?name= Andy "; Console.log (encodeURIComponent (URL)); encoded var afterurl = encodeuricomponent (URL); Console.log (decodeURIComponent (Afterurl)); Decoding result: 1.4 operation string Merging string 1.4.1 concat () connection string var txt1 = "abc"; var txt2 = "123"; Console.log (TX T2)); "Abc123"; 1.4.2 Slice () slice ("Take the starting position of the string", [end position]); [] Optional starting position must have an end position can be omitted var txt = "ABCEDF"; Txt.slice (3); From the txt inside the character of the 3rd (index number) beginning to take the end of the position omitted, always take to the last. Summary slice (3) from the beginning of the 3rd, take the Last Slice (3,6) 3 from the 3rd start to take 6 to the 6th index number, or from the left of the No. 0 start number. But not Pack 6. The starting position can be negative, and if it is negative, it is taken from the right to the left. var txt = "asdf"; Txt.slice (-1) The result is F 1.4.3 substr () substr (starting position, [number taken]) ibid. The number of non-write, by default from the starting position to the last. Number of takes: refers to starting from the starting position, the number of faces. var txt = "Abcdefghijk"; TXT.SUBSTR (3,4); The number of 4 DEFG substr (-1) starting from 3rd (d) is less error-ie678. Try to use less compatibility: Onbtnclick ("Btn7", Div1.substr (div1.length-1,1)); Compatible notation substring same as slice but with a little bit different substring (3,6) substring always takes a small value as the starting position of the large value as the end position for example: substring (6,3 ) In practice automatically becomes substring (3,6); 1.5 Reserved decimal places 122340.12345 reserved Two-bit valid decimals 122340.12 substr (0,. +3) 1.console.log (Str.substr (0,str.indexof (".") +3)); Intercept the String 2 Console.log (parseint (pi*100)/100) by indexOf the position of the decimal point; Multiply by 100 and then divide by 3 Console.log (pi.tofixed (2));p i.tofixed (2) reserved 2-bit decimal 1.6-case Conversion ASDF = ASDF ASDF--ASDF 1 toUpperCase, converted to uppercase (parameter: none) 2 tolowercase, converted to lowercase (parameter: none) Asdf.touppercase () The result is: ASDF $ ("txt"). Value.touppercase (); Convert the value of txt to uppercase 1.7 seamless scrolling principle: first copy two pictures (first and second) to the last (essentially 5.6) UL is the box move, if the left value of UL is greater than or equal to 4 picture width, it should be The quick recovery is 0. Complete code: 1<Script>2 varScroll=document.getElementById ("Scroll");3 varul=scroll.children[0];4 varNum= 0; //control left side value5 varTimer= NULL; //Timer6Timer=setinterval (AutoPlay, -);7 functionAutoPlay () {8Num--;9 //console.log (num);TenNum<=- - ?Num= 0: num; OneUl.style.left=Num+ "px"; A } -Scroll.onmouseover= function() { //Mouse over large box stop timer -clearinterval (timer); the } -Scroll.onmouseout= function() { -Timer=setinterval (AutoPlay, -); //Turn on Timer - } + </Script>1.8 Slow animation constant speed animation, look, the effect is too simple. Linear sequence: 2 4 6 8 10 easing animation formula: A box with an initial value of 0 to go to the position of the PX if the initial value leader 0 target Box.s Tyle.left = xxxx + "px" leader = leader + (Target-leader)/10; 1 Btn.onclick = function () {2 setinterval (function () {3 leader = leader + (Target-leader)/10;4 Box.style.left = leader + "px"; 5},30) 6}
JS Basic Knowledge 5