Home >Web Front-end >JS Tutorial >Summary of JavaScript basic knowledge and common methods_javascript skills
JAVASCRIPT is an indispensable part of AJAX technology, so if you want to learn AJAX and the popular AJAX framework well, learning JAVASCRIPT well is the most important.
1. Basic knowledge:
1.document.write(""); Output statement
2. The comment in JS is //
3. The traditional HTML document sequence is: document->html->(head,body)
4. The DOM sequence in a browser window is: window->(navigator, screen, history, location, document)
5. Get the name and value of the element in the form: document.getElementById("ID number of the element in the form").name (or value)
6. A JS that converts lowercase to uppercase: document.getElementById("output").value = document.getElementById("input").value.toUpperCase();
7. Value types in JS: String, Number, Boolean, Null, Object, Function
8. Convert character type in JS to numerical type: parseInt(), parseFloat()
9. Convert numbers in JS to character type: ("" variable)
10. The length of a string in JS is: (length)
11.Characters in JS are connected using the symbol.
12. The comparison operators in JS include: == equal to, != not equal to, >, >=, 3063134ec807af1ea9d3498f483bd755
49. Quote a file-style JS:e508589c3715add41f9ad96d32f35a1c2cacc6d41bbb37262a98f745aa00fbf0
50. Specify HTML to be displayed in browsers that do not support scripts:2b0b25ff593c5b6c03403dd6234ffb2cf920f363442462683100636cb2662870
51. When there are both hyperlinks and ONCLICK events, the old version of the browser will redirect to a.html, otherwise it will redirect to b.html. Example: baab5fe4585378502cd4dbb805c97b44dfsadf5db79b134e9f6b82c0b36e0489ee08ed
52. The built-in objects of JS are: Array, Boolean, Date, Error, EvalError, Function, Math, Number, Object, RangeError, ReferenceError, RegExp, String, SyntaxError, TypeError, URIError
53. Line breaks in JS:/n
54. Window full screen size:3f1c4e4b6b16bbbd69b2ee476dc4f83afunction fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;3fa3f474cbb4b6d948eebecb1be5dde4
55.all in JS represents all the elements below it
56. Focus order in JS: document.getElementByid("Form Element").tabIndex = 1
57.The value of innerHTML is the value of the form element: such as ab0cf0dc10fb83cfce1c239d3c0ef11e"how are 907fae80ddef53131f3292ee4f81644byoud1c6776b927dc33c5d9114750b586338"94b3e26ee717c64999d7867364b1b4a3, then the value of innerHTML is: how are < ;em>youd1c6776b927dc33c5d9114750b586338
58. The value of innerTEXT is the same as above, except that tags like 907fae80ddef53131f3292ee4f81644b will not be displayed.
59.contentEditable can set whether the element can be modified, and isContentEditable returns the status of whether it can be modified.
60.isDisabled determines whether it is a prohibited state. disabled sets the prohibited state
61.length gets the length and returns an integer value
62.addBehavior() is an external function file called by JS. Its extension is .htc
63.window.focus() puts the current window in front of all windows.
64.blur() means losing focus. It is the opposite of FOCUS().
65.select() means that the element is in the selected state.
66. Prevent users from entering text in the text box: onfocus="this.blur()"
67. Get the number of occurrences of this element on the page: document.all.tags("div (or other HTML tags)").length
68. There are two types of form output in JS: modal and non-modal.window.showModaldialog(),window.showModeless()
69. Status bar text setting: window.status='text', default status bar text setting: window.defaultStatus = 'text.';
70. Add to favorites: external.AddFavorite("http://www.dannyg.com","jaskdlf");
71. No action is taken when a script error is encountered in JS: window.onerror = doNothing; The syntax for specifying an error handle is: window.onerror = handleError;
72. Specify the parent window of the currently opened window in JS: window.opener, and support multiple continuations of opener.opener...
73.Self in JS refers to the current window
74. Content displayed in the status bar in JS: window.status="Content"
75.top in JS refers to the topmost frame in the frame set
76.Close the current window in JS: window.close();
77.JS中提出是否确认的框:if(confirm("Are you sure?")){alert("ok");}else{alert("Not Ok");}
78.JS中的窗口重定向:window.navigate("http://www.sina.com.cn");
79.JS中的打印:window.print()
80.JS中的提示输入框:window.prompt("message","defaultReply");
81.JS中的窗口滚动条:window.scroll(x,y)
82.JS中的窗口滚动到位置:window.scrollby
83.JS中设置时间间隔:setInterval("expr",msecDelay)或setInterval(funcRef,msecDelay)或setTimeout
84.JS中的模态显示在IE4+行,在NN中不行:showModalDialog("URL"[,arguments][,features]);
85.JS中的退出之前使用的句柄:function verifyClose(){event.returnValue="we really like you and hope you will stay longer.";}} window.onbeforeunload=verifyClose;
86.当窗体第一次调用时使用的文件句柄:onload()
87.当窗体关闭时调用的文件句柄:onunload()
88.window.location的属性: protocol(http:),hostname(www.example.com),port(80),host(www.example.com:80),pathname("/a/a.html"),hash("#giantGizmo",指跳转到相应的锚记),href(全部的信息)
89.window.location.reload()刷新当前页面.
89-1.parent.location.reload()刷新父亲对象(用于框架)
89-2.opener.location.reload()刷新父窗口对象(用于单开窗口)
89-3.top.location.reload()刷新最顶端对象(用于多开窗口)
90.window.history.back()返回上一页,window.history.forward()返回下一页,window.history.go(返回第几页,也可以使用访问过的URL)
91.document.write()不换行的输出,document.writeln()换行输出
92.document.body.noWrap=true;防止链接文字折行.
93.变量名.charAt(第几位),取该变量的第几位的字符.
94."abc".charCodeAt(第几个),返回第几个字符的ASCii码值.
95.字符串连接:string.concat(string2),或用+=进行连接
96.变量.indexOf("字符",起始位置),返回第一个出现的位置(从0开始计算)
97.string.lastIndexOf(searchString[,startIndex])最后一次出现的位置.
98.string.match(regExpression),判断字符是否匹配.
99.string.replace(regExpression,replaceString)替换现有字符串.
100.string.split(分隔符)返回一个数组存储值.
101.string.substr(start[,length])取从第几位到指定长度的字符串.
102.string.toLowerCase()使字符串全部变为小写.
103.string.toUpperCase()使全部字符变为大写.
104.parseInt(string[,radix(代表进制)])强制转换成整型.
105.parseFloat(string[,radix])强制转换成浮点型.
106.isNaN(变量):测试是否为数值型.
107.定义常量的关键字:const,定义变量的关键字:var
二:javascript常用方法如下:
1.index和indexof ,lastindexof
var arr = [1,2,3,4,5,4,3,2,1]; // 1个参数的时候表示传值,返回索引位置 (index 从零开始) var index = arr.indexOf(4); // 2个参数的时候,第一个参数表示起始位置 第二个参数还是值 var index = arr.indexOf(4,4); //alert(index)// 5
2.五个新迭加方法
// every :对于数组每一个元素进行一个函数的运行,如果都返回true 最后则返回true 如果有一个不满足条件,则返回false var result = arr.every(function(item,index,array){ return item > 2; }); alert(result); // filter:对于数组的每一个元素进行一个函数的运行 给定的函数去执行 把过滤后的结果返回 var result = arr.filter(function(item,index,array){ return item > 2; }); alert(result); // forEach:循环数组每一项的值,并执行一个方法 arr.forEach(function(item,index,array){ alert(item); }); //map 对于数组的每一个元素进行一个函数的运行 可以经过函数执行完毕后 把新的结果返回 var result = arr.map(function(item,index,array){ return item*2; }); alert(result) //some:对于数组每一个元素惊醒一个函数的运行,如果有一项返回true ,则返回true,如果有一个返回false 则返回false var result = arr.some(function(item,index,array){ return item >=5; }); alert(result); // reduce reduceRight // 前一个 值,当前值,索引位置,array var result = arr.reduce(function(prev,cur,index,array){ return prev + cur; }); alert(result);// 25 var result = arr.reduceRight(function(prev,cur,index,array){ return prev + cur; }); alert(result)//25