SoFunction
Updated on 2025-04-06

JavaScript Basic Introduction Syntax Collection Page 3/3


A warning message pops up

<script language=”JavaScript”>
<!--
(“Hello”);
// -->
</script>

A confirmation box pops up

<script language=”JavaScript”>
<!--
var result = (“Click OK to continue”);
// -->
</script>

Define functions

<script language=”JavaScript”>
<!--
function multiple(number1,number2) {
var result = number1 * number2;
return result;
}
// -->
</script>

Calling JS functions

<a href=”#” onClick=”functionName()”>Link text</a>
<a href="/”javascript:functionName"()”>Link text</a>

Execute the function after the page loads

<body onLoad=”functionName();”>
Body of the page
</body>

Conditional judgment

<script>
<!--
var userChoice = (“Choose OK or Cancel”);
var result = (userChoice == true) ? “OK” : “Cancel”;
(result);
// -->
</script>

Specify the number of times to cycle

<script>
<!--
var myArray = new Array(3);
myArray[0] = “Item 0”;
myArray[1] = “Item 1”;
myArray[2] = “Item 2”;
for (i = 0; i < ; i++) {
(myArray + “<br>”);
}
// -->
</script>

Set future execution

<script>
<!--
function hello() {
(“Hello”);
}
(“hello()”,5000);
// -->
</script>

Timed execution function

<script>
<!--
function hello() {
(“Hello”);
(“hello()”,5000);
}
(“hello()”,5000);
// -->
</script>

Cancel the timing execution

<script>
<!--
function hello() {
(“Hello”);
}
var myTimeout = (“hello()”,5000);
(myTimeout);
// -->
</script>

Execute functions when page uninstall
<body onUnload=”functionName();”>
Body of the page
</body>
Previous page123Read the full text