Javascript Basics

1. The DOM order in a browser window is: window->(navigator,screen,history,location,document)
2. The traditional HTML document order is: document->html->(head,body)
3. Get the form The name and value of the element in

document.getElementById("ID").name
document.getElementById("ID").value

4. Value types in JS: String, Number, Boolean, Null, Object, Function
5. Character conversion in JS

String to Number
ECMAScript provides two methods for converting non-numeric primitive values ​​to numbers, namely parseInt() and parseFloat().

parseInt('123abc') : 返回 123(int)
parseFloat('31.24abc') : 返回 31.24

number to string

var i = 10;
var s = i.toString();  //将输出 String  "10"

coercion

Boolean(value) - 把给定的值转换成 Boolean 型;
Number(value) - 把给定的值转换成数字(可以是整数或浮点数);
String(value) - 把给定的值转换成字符串;

6. The command to terminate the loop is: break
7. When there are multiple form forms in the file. You can use document.forms[0], document.forms[1] instead
8. Window: open the window window.open(), Close a window: window.close(), the window itself: self
9. Status bar settings: window.status= “character”
10. Pop-up confirmation box: window.confirm();
11. Pop-up input prompt box: window. prompt();
12. Specify the location where the link is currently displayed: window.location.href= “URL”
13. Take out the number of all forms in the form: document.forms.length
14. Close the output stream of the document: document.close ();
15. Create a document element

createElement(name) 通过指定名称创建一个元素节点
createTextNode(data) 创建文本节点。

16. Methods to get elements

document.getElementById(id)  
document.getElementsByName(name)  //返回带有指定名称的对象的集合
document.getElementsByTagName(tagname)  //返回带有指定标签名的对象的集合

17. String case conversion

string.toUpperCase();  //转换成大写
string.toLowerCase();  //转换成小写

18. Return the position where string 2 appears in string 1: String1.indexOf( "String2 ")!=-1it means not found.
19. Take a character at the specified position in the string: StringA.charAt(9);
20. Take the substring of the specified start and end points in the string: stringA.substring(2,6);
21 . Mathematical functions

Math.PI  //(返回圆周率)
Math.SQRT2  //(返回开方)
Math.max(value1,value2)  //返回两个数中的最在值
Math.pow(value1,10)  //返回value1的十次方
Math.round(value1)  //四舍五入函数
Math.floor(Math.random()*(n 1))  //返回隨机数 

22. Define date variables: var today = new Date();
23. List of date functions Note : This date and time starts from 0

dateObj.getTime()  //得到时间,
dateObj.getYear()  //得到年份
dateObj.getFullYear()  //得到四位的年份
dateObj.getMonth()  //得到月份
dateObj.getDate()  //得到日
dateObj.getDay()   //得到日期几
dateObj.getHours()  //得到小时
dateObj.getMinutes()  //得到分
dateObj.getSeconds()  //得到秒
dateObj.setTime(value)  //设置时间
dateObj.setYear(val)  //设置年
dateObj.setMonth(val)  //设置月
dateObj.setDate(val)  //设置日
dateObj.setDay(val)  //设置星期几
dateObj.setHours  //设置小时
dateObj.setMinutes(val)  //设置分
dateObj.setSeconds(val)  //设置秒 

24. The parent window that opens the child window is: opener
25. Indicates the current position: this
26. contentEditableIt can be set whether the element can be edited/modified, and isContentEditablewhether it can be modified or not.
27. window.focus()Make the current window in front of all windows.
28. blur()Refers to losing focus. FOCUS()On the contrary // When the element gains focus, a focus event occurs.
29. select()The method is used to select the text in the password field.
30. The input text box prohibits input, preventing users from prohibiting input in the text box
. HTML provides three kinds of input prohibiting input boxes: readonly、disabled、autocomplete。strictly speaking, the first two are prohibiting user input, and autocomplete only clears the user's input record by default.

<input type="text" name="www.xxx" readonly="readonly" />   //表示该输入域的值只能read,不能write,他仅仅只能与 type="text" 配合使用,可复制,可选择,可以接收焦点,后台会接收到传值。
<input type="text" name="www.xxx.com" disabled="disabled" />   //表示禁用input元素,不可编辑,不可复制,不可选择,不能接收焦点,后台也不会接收到传值,页面显示也会变成置灰状态。
<input type="text" autocomplete="off" id="number"/>   //浏览器通常会记录input输入框的记录,所以在输入的时候,经常会下拉很多内容,使用autocomplete能够清除用户的输入记录,在每次重新请求页面时,记录都会清空。

31. Get the number of occurrences of the element on the page

document.all.tags( "div(或其它HTML標记符) ").length   //取出该元素在页面中出现的数量
document.all.tags("input")  //取到当前所有的input标签
document.all.tags("input").item(0)  //就是第一个input标签
document.all.tags("input").item(0).checked  //第一个标签被选中

32. Prompt input box in JS: window.prompt( "message ", "defaultReply ");
33. Window scroll bar window.scroll(x,y)
in JS: 34. Window scrolling to position window.scrollby
in JS: 35. Set time interval in JS: setInterval( "expr ",msecDelay)or setInterval(funcRef,msecDelay)or setTimeout
36. Refresh the current page window.location.reload()
37. window.history.back()Return to the previous page , window.history.forward()return to the next page, window.history.go(return the number of pages, you can also use the visited URL)
38. document.write()Output without line document.writeln()wrapping, line-wrapped output
39. document.body.noWrap=true;Prevent the link text from wrapping.
40. 变量名.charAt(第几位), Take the first character of the variable.
41. "abc ".charCodeAt(第几个), Return the ASCii code value of the first few characters.
42. string.replace(regExpression,replaceString)Replace the existing string
43. string.split(分隔符)Return an array to store the value
44. string.substr(start[,length])Take the string from the first bit to the specified length.
45. string.toLowerCase()Make the string all lowercase
46. string.toUpperCase()​​Make all characters uppercase.
47. parseInt(string[,radix(代表进制)])Force conversion to integer type.
48. parseFloat(string[,radix])Force conversion to floating point type
49. : isNaN(变量)Test whether it is a numeric
typeconstvar

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325708378&siteId=291194637