SoFunction
Updated on 2025-04-03

Basics of javascript

1. URL is the address of the window to be opened name is the name of a new window, and you can communicate with the new window through name features are strings divided with "," such as "height:width:200", whose content is various properties of a new window

2. window provides a display scheme for modal dialog: showModalDialog(paramparam// Parameter 1: Used to specify the URL that provides the HTML content of the dialog box Parameter 2: It can be an arbitrary value. This value can be accessed through the value of the window.dialogArguments property in the script in the dialog box. Parameter 3: It is a non-standard list, containing name=value pairs separated by semicolons. If this parameter is provided, you can configure the dimensions and other properties of the dialog box, and use dialogwidth and dialogheight to Set the size of the dialog window, use "resizable=yes" to allow the user to change the window size

3. varnum=076;//The octal system represented by it starts with 0. If the following value exceeds the range of 8, such as: 079, etc., then parse it in decimal.

4. parent.appendChild(child)// method can insert a child element into the parent element Including two parts of work: 1-Insert the text node into

Under the node, para.appendChild(txt);2-

Insert nodes into other nodes

5. You can create an editable area element in HTML. Method:

6、

7. The content of many nodes is not in their value, such as:

Helloworld

, you can use vartext=document.getElementById("desc").firstChild.nodeValue; The value obtained by text here is: HelloWorld

8. Right shift is divided into two types: signed right shift and unsigned right shift:

9. JavaScript has no block-level scope, as shown in the following example:

10. Signed right shift: >> only move data bits, not sign bits: -64>>5---->-2 Unsigned right: >>> Everything needs to move, so the negative number will become a positive number after it moves, and this positive number is generally very large

11. There are three types of objects: user-defined-object (user-defined object), native-object (built-in object) and host-object (host object) where native-object is an object built into javascript, such as Array, Math, Date, etc., while host-object is an object provided by the browser.

12. NaN->NotaNumber;//Non-number, NaN is not equal to any value, so it is self-contained; the way to determine whether a value can be converted into a numeric value: isNaN(*), * is the data to be converted

13. If the conversion is performed using parseInt() method, it is different from 7 (for strings). The basic principle is as follows:

14. In JavaScript, 32-bit data represent a number, shift left <<不会改变符号位,例:2<<5;-->64 i.e.: 10->1000000

15. slice() returns a fragment of the specified array. You can write two parameters or one parameter. One parameter represents starting from the current position of the parameter and ending. The two parameters refer to the first parameter to the second parameter. Parameters - specifies the last element, that is, the penultimate element, and -3 specifies the penultimate element

16. window.location.href// can get the URL address loaded by the current document, window.location.search// can get the content after the ? characters in the current document, which is generally used for Detect the situation where key-value pairs, name=value

17. JavaScript has 5 basic data types, Undefined, Null, Boolean, Number and String; and a complex data type: Object

18. Open a new window in JavaScript with window.open(url, name, features). These three parameters are all optional, as follows:

19. The important attributes of Node nodes are explained as follows: parentNode---->To the parent node of the node, if it is a document object, its parent node is null childNodes---->Read-only class array node, it is a child node of that node firstChild and lastChild, the first child and the last child of the node nextSibling, previousSibling, the previous and next ones of the brother nodes of this node nodeType---->The node type of this node is to return a value, 9 represents the document node, 1 represents the Element node, 3 represents the Text node, 8 represents the Comment node, and 11 represents the DocumentFragment node nodeValue----->text node or Comment node text content nodeName---->The label name of the element, expressed in capital form

20. msg="hello";//If you do not apply to var, you can declare a global variable. However, because this variable is global, it can easily cause some problems with other calls, so it is not recommended.

21. Array operation:

22. The case in the switch statement is very powerful, it can be a numeric value, a string or even an expression

23. varmsg;//Declare a variable. Before assigning a value to this variable, the variable is named: undefined

24. There is no parameter added in function() in javascript, for it, it is actually received by arguments[]

25. Setting the variable value to null can dereference this variable. JavaScript's garbage collector will recycle it when it is run next time.

26. Screen object can obtain information about the size of the window display and the number of available colors.

27. The instanceof statement is used to determine whether it belongs to a certain data type or an object: personinstanceofObject//The variable person is Object? If so, it returns true.

28. Reference types are similar to classes, but not the same thing! There are two ways to create a reference type:

29. The toString() method generally does not need to use parameters. true->"true" is converted according to strings, but when converted from numbers to String, parameters can be added to set the partition.

30. Whether it is setTimeout or setInterval to setTimeout, it is not executed immediately, but put this method into the queue and wait for the previous state to be executed before execution.

31. SetTimeout()//Two parameters, one is the callback function, and the other is the callback time, indicating how many milliseconds it is to call this callback function, such as:

32. When converting to Number, false->0;true->1;""->0;"00022"->22;"helloworld"->NaN; Note: The Number() method is used

33. getElementsByClassName(); can get the child nodes of the same className under the parent node

34. The navigator attribute of window can contain multiple attributes: appName---->The full name of the web browsing area appVersion----->Browser Manufacturer and Version userAgent---->usually contains appVersion and other information, without a certain format platformfrom----->Operation system that runs the browser, it is possible to even make the hardware onLine---->If this property exists, it means whether the current browser is connected to the network. geolocation----->Interface used to determine user geolocation information

35. Parses the first non-space character of String. If it is a space, skip it. If it is a non-number or a negative sign, it will directly return to NaN; Continue to parse the contiguous characters until they encounter non-numbers or parsing is completed, and return the parsed content; If the non-space characters parsed to the string start with 0x and add hexadecimal characters after it will be converted to hexadecimal. If it starts with 0 and adds english characters after it will be converted to english;

36. Due to historical reasons, only

,And those with href attribute, document.forms.id//name is the id of form tag, and other elements are not allowed

37. Method to insert a new element into the html document:

38. The length attribute represents length join() method:

39. It is a combination of

40. Methods to set css attributes for Element:

41. varnum=0x22;//represents hexadecimal

42. concat()//Create and return a new array, which is used to concatenate arrays, which are connected to elements in the array rather than the array itself

43. varnowtime=newDate();nowtime.toLocaleTimeString(); can display the current time (Note: it is time but does not include date)

44. Windows provides three dialog boxes alert-->Prompt dialog box confirm()-----> also displays a message, but requires the user to determine or cancel, example: varcorrect=confirm("helloworld"); if(correct){returntrue} prompt()----->Show a message, wait for user input and return to that string

45. Click event for an element: vartempelement=document.getElementById("xx");tempelement.onclick=function(){alert("Hello");};

46. ​​You can also use parseInt(*,*) method. The latter variable represents the division to be converted; you can choose 2, such as parseInt("10",->At this time, no need to add 0x or 0

47. Create a new element (including its content, etc.) Insert this new element into the number of nodes

48. setInterval(func,time);//It is used to register the function called repeatedly after the specified time. Func is the function called repeatedly, time is the specified time, unit milliseconds And clearInterval(h); is an event used to unregister, where h is varh=setInterval(func,time);

49. The name attribute can also be used to obtain certain elements, but the name attribute is only valid in a few html elements: form,Form Elements,

//This method is to use the javascript pseudo-protocol to call the javascript method. This method is not recommended because different browsers support this pseudo-protocol differently.

51. Methods for loading two functions in window.onload window.onload=function(){ // Write two functions here func1(); func2(); }

52. The set and get methods can also set properties for an object, called memory properties, which can implement relatively complex operations, such as:

53. window.location="https://www.jbnet/";// can be used to open web pages