English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Website effects离不开脚本,JavaScript是最常用的脚本语言,我们归纳一下常用的基础函数和语法:
1.输出语句:document.write("");
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value)
6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型转换成数值型:parseInt(),parseFloat()
9.JS中的数字转换成字符型:(""+变量)
10.JS中的取字符串长度是:(length)
11.JS中的字符与字符相连接使用+.号.
12.JS中的比较操作符有:==等于,!=不等于,>,>=,<.<=
13.JS中声明变量使用:var来进行声明
14.JS中的判断语句结构:if(condition){}else{}
15.JS中的循环结构:for([initial exPRession];[condition];[upadte expression]) {inside loop}
16.循环中止的命令是:break
17.JS中的函数定义:function functionName([parameter],...){statement[s]}
18When there are multiple form forms in the file. You can use document.forms[0], document.forms["}}1] instead.
19The window: open a window window.open(), close a window: window.close(), the window itself: self
20. Set the status bar: window.status="character";
21Pop up a prompt message: window.alert("character");
22Pop up a confirmation box: window.confirm();
23Pop up an input prompt box: window.prompt();
24Specify the current display link position: window.location.href="URL" rel="external nofollow"
25Get the number of all forms in the window: document.forms.length
26Close the output stream of the document: document.close();
27The string concatenation symbol:+=
28Create a document element: document.createElement(), document.createTextNode(),
29The method to get an element: document.getElementById(),
30. Set the value of all text members in the form to empty:
var form = window.document.forms[0] for (var i = 0; i<form.elements.length;i++){ if (form.elements[i].type == "text"){ form.elements[i].value = ""; } }
31The judgment of whether a checkbox is selected in JS: document.forms[0].checkThis.checked (the checked property represents whether it is selected and returns TRUE or FALSE)
32The length of a radio button group (the names of radio buttons must be the same): document.forms[0].groupName.length
33The judgment of whether a radio button group is selected also uses checked.
34The value of a dropdown list box: document.forms[0].selectName.options[n].value (n is sometimes used with the dropdown list box name and selectedIndex to determine the selected value)
35The definition of a string: var myString = new String("This is lightsWord");
36.Convert string to uppercase: string.toUpperCase(); Convert string to lowercase: string.toLowerCase();
37.Returns the string2in the string1position in the string: String1.indexOf("String2)) !=-1means not found.
38.Get a character at a specified position in a string: StringA.charAt(9);
39.Extract a substring from a string with a specified starting and ending point: stringA.substring(2,6);
40. Mathematical functions: Math.PI (returns the circumference), Math.SQRT2(returns the square root), Math.max(value1,value2) returns the maximum of the two numbers, Math.pow(value1,10) returns value1to the power of ten, Math.round(value1) rounding function, Math.floor(Math.random(),*(n+1)) returns a random number
41.Define a date variable: var today = new Date();
42.List of date functions:
dateObj.getTime() gets the time,
dateObj.getYear() gets the year,
dateObj.getFullYear() gets the four-digit year,
dateObj.getMonth() gets the month,
dateObj.getDate() gets the day,
dateObj.getDay() gets the day of the week,
dateObj.getHours() gets the hour,
dateObj.getMinutes() gets the minutes,
dateObj.getSeconds() gets the seconds,
dateObj.setTime(value) sets the time,
dateObj.setYear(val) sets the year,
dateObj.setMonth(val) sets the month,
dateObj.setDate(val) sets the day,
dateObj.setDay(val) sets the day of the week,
dateObj.setHours sets the hour,
dateObj.setMinutes(val) sets the minutes,
dateObj.setSeconds(val) sets the seconds [Note: This date and time starts from 0]
43.FRAME representation method:
[window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName
44.parent represents the parent object, top represents the topmost object
45.The parent window of the opened popup window is: opener
46.Represents the current position: this
47.When calling a JS function in a hyperlink, use:(javascript:) at the beginning followed by the function name
48.This JS will not be executed in old browsers:<!-- //-->
49.Reference a file-based JS:<script type="text/Javascript" src="aaa.js"></script>
50. Specify the HTML to be displayed in browsers that do not support scripts:<noscript></noscript>
51.When both hyperlink and ONCLICK events are present, the old version of the browser will redirect to a.html, otherwise to b.html. Example:<a href="a.html" rel="external nofollow" onclick="location.href='b.html';return false">dfsadf</a>
52.JS built-in objects include: Array, Boolean, Date, Error, EvalError, Function, Math, Number, Object, RangeError, ReferenceError, RegExp, String, SyntaxError, TypeError, URIError
53.In JS, the newline character is:\n
54.The full-screen size of the window:
<script>function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth;this.outerHeight=screen.availHeight;}window.maximize=fullScreen;</script>
55.In JS, 'all' represents all the elements below ithttp://bizhi.knowsky.com/
56.The focus order in JS: document.getElementById("form element").tabIndex = 1
57.The value of .innerHTML is the value of the form element: such as <p id="para">"how are <em>you</em>"/p>, then the value of innerHTML is: how are <em>you</em>
58.The value of .innerTEXT is the same as the one above, but it will not display tags like <em>.
59.contentEditable can set whether the element can be modified, isContentEditable returns whether it can be modified.
60.isDisabled determines whether it is in the disabled state.disabled sets the disabled state
61.length gets the length, returns an integer value
62.addBehavior() is an external function file called by JS, with the extension .htc
63.window.focus() brings the current window to the front of all windows.
64.blur() means losing focus. The opposite of FOCUS().
65.select() indicates 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 the element in the page: document.all.tags("div"(or other HTML tag)).length
68.JS has two types of window output: modal and modeless. window.showModaldialog(), window.showModeless()
69.Set status bar text: window.status='text', default status bar text setting: window.defaultStatus = 'text.';
70.Add to favorites: external.AddFavorite("http://www.xrss.cn","jaskdlf;
71.JS do nothing when encountering script errors: window.onerror = doNothing; The syntax for specifying the error handler is: window.onerror = handleError;
72.JS specify the parent window of the currently opened window: window.opener, supports multiple continuation with opener.opener...
73.JS 'self' refers to the current window
74.JS display content on the status bar: window.status="content"
75.JS 'top' refers to the topmost frame in the frame set
76.JS close the current window: window.close();
77.JS confirmation box: if(confirm("Are you sure"63;")){alert("ok");}else{alert("Not Ok");}
78.JS window redirection: window.navigate("http://www.sina.com.cn;
79.JS print: window.print();
80.JS prompt input box: window.prompt("message","defaultReply");
81.Window scrollbar in JS: window.scroll(x,y)
82.Window scrolls to the specified position in JS: window.scrollby
83.Set time interval in JS: setInterval("expr",msecDelay) or setInterval(funcRef,msecDelay) or setTimeout
84.Modal display in IE with JS4+works in NN, but not in IE: showModalDialog("URL"[,arguments][,features]);
85.The file handle used before exiting in JS: function verifyClose(){event.returnValue="we really like you and hope you will stay longer.";}} window.onbeforeunload=verifyClose;
86.The file handle used when the window is first called: onload()
87.The file handle called when the window is closed: onunload()
88.window.location's properties: protocol(http:), hostname(www.example.com), port(80), host(www.example.com:80), pathname("/a/a.html"), hash("#giantGizmo", jumps to the corresponding anchor), href(all information)
89.window.location.reload() refreshes the current page.
89-1.parent.location.reload() refreshes the parent object (used for frames)
89-2.opener.location.reload() refreshes the parent window object (used for single windows)
89-3.top.location.reload() refreshes the topmost object (used for multiple windows)
90.window.history.back() returns to the previous page, window.history.forward() returns to the next page, window.history.go(to which page, or you can also use the visited URL)
91.document.write() outputs without line breaks, and document.writeln() outputs with line breaks.
92.document.body.noWrap=true; to prevent the wrapping of link text.
93.The character at the specified position of the variable name, retrieves the character at the specified position of the variable.
94."abc".charCodeAt(the nth), returns the ASCII code value of the nth character.
95.String concatenation: string.concat(string2), or use+= for concatenation
96.variable.indexOf("character",start position): Returns the first occurrence position (starting from 0)
97.string.lastIndexOf(searchString[,startIndex]): The last occurrence position.
98.string.match(regExpression): Determine if the characters match.
99.string.replace(regExpression,replaceString): Replace the existing string.
100.string.split(separator): Returns an array storing the values.
101.string.substr(start[,length]): Take a string from the start position to the specified length.
102.string.toLowerCase(): Make the string all lowercase.
103.string.toUpperCase(): Make all characters uppercase.
104.parseInt(string[,radix(representing the number system)]): Force conversion to an integer type.
105.parseFloat(string[,radix]): Force conversion to a floating-point type.
106.isNaN(variable): Test if it is a numeric type.
107.The keyword for defining constants: const, the keyword for defining variables: var
That's all for this article. I hope the content of this article can bring a certain amount of help to everyone's learning or work, and also hope to get more support for the Shouting Tutorial!
Statement: The content of this article is from the network, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been edited by humans, and does not assume any relevant legal responsibility. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report abuse, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)