May 29, 2021 Article blog
The JavaScript function is similar to Java's approach, allowing you to complete blocks of code for a specific task and try it out directly.
Function classification: Custom functions and system functions
Common system functions
ParseInt
("String"): Converts a string to an integer number
example:
ParseInt ("86a") output is 86
ParseInt ("86a21") output is 86
ParseInt ("a86a") output is NaN
ParseFloat
("String"): Converts a string to a floating-point number
example:
The parseFloat ("34.34") output is a floating-point value of 34.34
isNaN(): Used to check if it is a non-number
IsNaN ("111") outputs false
IsNaN(true) output false
IsNaN ("true") outputs true
IsNaN ("aaa") outputs true
IsNaN ("111a") outputs true
Function calls are generally used in conjunction with form element events, and their format is called
Event name: "Function name ()"
instance:
function study( ){
for(var i=0;i<5;i++){
document.write("<h4>欢迎学习JavaScript</h4>");
}
}
Click the button to call study() to execute the code of the function body
<input name="btn" type="button"
value="显示5次欢迎学习JavaScript" onclick="study( )" />
instance:
function study(count){
for(var i=0;i<count;i++){
document.write("<h4>欢迎学习JavaScript</h4>");
}
}
Click the button to call study (count) to execute the code of the function body
<input name="btn" type="button" value="请输入显示欢迎学习JavaScript的次数"
onclick="study(prompt('请输入显示欢迎学习JavaScript的次数:',''))" />
That's all you need to know about JavaScript functions.