Home > Web Front-end > JS Tutorial > What is the javascript method called by jsp?

What is the javascript method called by jsp?

醉折花枝作酒筹
Release: 2023-01-07 11:44:51
Original
8100 people have browsed it

Method: 1. Use the "οnclick="function()"" method to directly specify which js function to use; 2. Import the js file, and then add id and class to the tag (you can also use tags OK, but make sure there is only one tag of this tag on the page or specify a certain tag. If multiple tags are matched, an error will be reported).

What is the javascript method called by jsp?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

First create a js file, such as index.js

Write js code:

function subCheck(){
    alert("are you sure to submit?");
}

window.onload = function () {
    var button1 = document.getElementById("btn");
    button1.onclick = function () {
        alert("you click button!!!")
    }
}
Copy after login

Call js functions in jsp files

The first step is to add the script tag to the head

In jsp, there are two types of functions that reference js Method:

The first method is our most commonly used method is to use οnclick="function()" method to directly specify which js function to use. Remember to introduce the js file in the head

<input type="submit" value="提交" onclick="subCheck()">
Copy after login

The second method is also very common: import a js file and then add id and class to the tag (you can also use tags, but you must ensure that the page has only one tag or specify a certain tag. If you match multiple tags, an error will be reported)

After loading js, first get the id or class or label and then use id.onclick = function(){} to execute the function. In jquery, use id.click(function(){})

<button id="btn">click me</button>
Copy after login

[Recommended Study: javascript advanced tutorial

The above is the detailed content of What is the javascript method called by jsp?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template