简体   繁体   English

如何从另一个jsp函数调用一个jsp的javascript函数

[英]how to call javascript function of one jsp from another jsp function

I have hello() javascript fuction in file1.jsp. 我在file1.jsp中有hello()JavaScript功能。 I want to call hello() by file2.jsp. 我想通过file2.jsp调用hello()。 file1.jsp has file1.jsp有

<html>
<script>
function hello()
{
...
}
</script>
</html>

I want to call this hello() function from file2.jsp 我想从file2.jsp调用此hello()函数

Perform the steps below: 执行以下步骤:

Move the script in page1.jsp file to a new JavaScript file eg main.js file and place the file in new folder eg js inside your WebContent folder. 将page1.jsp文件中的脚本移动到新的JavaScript文件(例如main.js文件),并将该文件放置在WebContent文件夹内的新文件夹(例如js)中。

Link main.js in page1.jsp file by putting below link in the section: 通过在部分中放置以下链接,链接page1.jsp文件中的main.js:

/js/main.js"> Do the same in page2.jsp file. /js/main.js“>在page2.jsp文件中执行相同的操作。

This way, same javascript code will be available for use in both page1.jsp and page2.jsp files. 这样,在page1.jsp和page2.jsp文件中都可以使用相同的javascript代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM