Commonly used attribute methods in JavaScript include: 1. The comment in JS is [//]; 2. Convert character type to numeric type [parseInt()]; 3. Get the length of the string [length]; 4. Use var to declare variables; 5. Judgment statement structure [if(condition){}else{}].
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.
Commonly used attribute methods in JavaScript are:
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 lowercase to uppercase JS:
document.getElementById("output").value=document.getElementById("input").value.toUpperCase();
7. Value types in JS: String, Number, Boolean, Null, Object, Function
8. Convert character types into numerical types in JS: parseInt(), parseFloat()
9. Convert numbers in JS to character type: ("" variable)
10. Get the string length in JS: (length)
11.JS Characters are connected with characters using numbers.
12. The comparison operators in JS are: ==Equal,!=Not equal,>;,>;=,<.>
13. Use var to declare variables in JS.
14. Judgment statement structure in JS: if(condition){}else{}
15.JS The loop structure in: for([initial expression];[condition];[upadte expression]) {inside loop}
16. The command to terminate the loop is: break
17. In JS Function definition: function functionName([parameter],...){statement[s]}
18. When multiple form forms appear in the file, you can use document.forms[0],document. forms[1] instead.
19. Window: Open the window window.open(), close a window: window.close(), the window itself: self
20. Status bar Setting: window.status="Character";
21. Pop-up prompt message: window.alert("Character");
22. Pop-up confirmation box: window.confirm();
23. Pop up the input prompt box: window.prompt();
24. Specify the location of the currently displayed link: window.location.href="URL"
25. Get the number of all forms in the form: document.forms.length
26. Close the output stream of the document: document.close();
27. String append connector: =
28. Create a document element: document.createElement(),document.createTextNode()
29. Get the element method: 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.type == "text"){ form.elements.value = ""; } }
31. Determine whether the check button is checked in JS:
document.forms[0].checkThis.checked
(The checked attribute represents whether it is selected and returns TRUE or FALSE )
32. Radio button group (the names of the radio buttons must be the same):
Get the length of the radio button group document.forms[0].groupName.length
33. Checked is also used to determine whether the radio button group is selected.
34. The value of the drop-down list box:
document.forms[0].selectName.options[n].value
(nSometimes the name of the drop-down list box plus .selectedIndex is used to determine Determine the selected value)
35. Definition of string: var myString = new String("This is lightsword");
36. Convert string to uppercase: string.toUpperCase( ); Convert the string to lowercase: string.toLowerCase();
37. Return the position where string 2 appears in string 1: String1.indexOf("String2")!=-1 means there is no Find.
38. Get a character at the specified position in the string: StringA.charAt(9);
39. Get the substring with the specified starting point and end point in the string: stringA. substring(2,6);
40. Math functions:
Math.PI (returns pi), Math.SQRT2 (returns square root), Math.max(value1, value2) returns The
of the two numbers is the most valuable, Math.pow(value1,10) returns the tenth power of value1, Math.round(value1) rounding function,
Math.floor(Math .random()*(n 1)) returns a random number
41. Define date variable: var today = new Date();
42. Date function list:
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 date,
dateObj.getHours() gets the hours, dateObj.getMinutes() gets the minutes, dateObj.getSeconds() gets seconds,
dateObj.setTime(value)设置时间,dateObj.setYear(val)设置年,
dateObj.setMonth(val)设置月,dateObj.setDate(val)设置日,
dateObj.setDay(val)设置星期几,dateObj.setHours设置小时,dateObj.setMinutes(val)设置分,
dateObj.setSeconds(val)设置秒 [注意:此日期时间从0开始计]
43.FRAME的表示方式:
[window.]frames[n].ObjFuncVarName,frames["frameName"].ObjFuncVarName,frameName.ObjFuncVarName
44.parent代表父亲对象,top代表最顶端对象
45.打开子窗口的父窗口为:opener
46.表示当前所属的位置:this
47.当在超链接中调用JS函数时用:(javascript :)来开头后面加函数名
48.在老的浏览器中不执行此JS:;
49.引用一个文件式的JS:;
50.指定在不支持脚本的浏览器显示的HTML:
51.当超链和onCLICK事件都有时,则老版本的浏览器转向a.html,否则转向b.html.
例:
<a href="a.html" onclick="location.href='b.html';return false">;dfsadf</a>;
52.JS的内建对象有:
Array,Boolean,Date,Error,EvalError,Function,Math,Number,Object,RangeError,
ReferenceError,RegExp,String,SyntaxError,TypeError,URIError
53.JS中的换行:\n
54.窗口全屏大小:
<script>;function fullScreen(){ this.moveTo(0,0);this.outerWidth=screen.availWidth; this.outerHeight=screen.availHeight;}window.maximize=fullScreen;</script>;
55.JS中的all代表其下层的全部元素
56.JS中的焦点顺序:document.getElementByid("表单元素").tabIndex = 1
57.innerHTML的值是表单元素的值:
如
;"how are ;you;"
;,则innerHTML的值就是:how are ;you;58.innerTEXT的值和上面的一样,只不过不会把;这种标记显示出来.
59.contentEditable可设置元素是否可被修改,isContentEditable返回是否可修改的状态.
60.isDisabled判断是否为禁止状态.disabled设置禁止状态
61.length取得长度,返回整型数值
62.addBehavior()是一种JS调用的外部函数文件其扩展名为.htc
63.window.focus()使当前的窗口在所有窗口之前.
64.blur()指失去焦点.与FOCUS()相反.
65.select()指元素为选中状态.
66.防止用户对文本框中输入文本: onfocus="this.blur()"
67.取出该元素在页面中出现的数量: document.all.tags("div(或其它HTML标记符)").length
68.JS中分为两种窗体输出:模态和非模态. window.showModaldialog(),window.showModeless()
69.状态栏文字的设置:
window.status='文字',默认的状态栏文字设置:window.defaultStatus = '文字.';
70.添加到收藏夹:
external.AddFavorite("http://meil.cnblogs.com";,"jaskdlf");
71.JS中遇到脚本错误时不做任何操作:
window.onerror = doNothing; 指定错误句柄的语法为:window.onerror = handleError;
72.JS中指定当前打开窗口的父窗口: window.opener,支持opener.opener...的多重继续.
73.JS中的self指的是当前的窗口
74.JS中状态栏显示内容:window.status="内容"
75.JS中的top指的是框架集中最顶层的框架
76.JS中关闭当前的窗口:window.close();
77.JS中提出是否确认的框:if(confirm("Are you sure?")){alert("ok");}else{alert("Not Ok");}
78.JS中的窗口重定向:window.navigate("http://meil.cnblogs.com";);
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.=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()刷新当前页面.
parent.location.reload()刷新父亲对象(用于框架).
opener.location.reload()刷新父窗口对象(用于单开窗口).
top.location.reload() refreshes the top object (for multiple windows)
90.window.history.back() returns to the previous One page, window.history.forward() returns to the next page,
window.history.go (return to which page, you can also use the visited URL)
91.document. write() does not wrap the output, document.writeln() wraps the output
92.document.body.noWrap=true; prevents the link text from wrapping.
93.Variable name.charAt( Which number), takes the character of the variable.
94. "abc".charCodeAt (what number), returns the ASCii code value of the character.
95. String connection: string.concat(string2), or use = to connect
96. Variable.indexOf("Character", starting position), returns the first occurrence position (starting from 0 Calculate)
97.string.lastIndexOf(searchString[,startIndex])The last occurrence position.
98.string.match(regExpression), determine whether the characters match.
99.string.replace(regExpression,replaceString) replaces the existing string.
100.string.split(separator) returns an array to store the value.
101.string.substr (start[,length]) takes the string from the digit to the specified length.
102.string.toLowerCase() makes the string all lowercase.
103.string. toUpperCase() makes all characters uppercase.
104.parseInt(string[,radix(representing base)]) is forced to be converted to an integer type.
105.parseFloat(string[, radix]) is forced to convert to a floating point type.
106.isNaN (variable): Test whether it is a numeric type.
107. Keywords for defining constants: const, keywords for defining variables :var
Related free learning recommendations: javascript video tutorial
The above is the detailed content of What are the commonly used attribute methods in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
