javascript 如何在 JSP 中的 onClick(按钮)上调用 Java Script 函数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8234965/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:44:52  来源:igfitidea点击:

How to call Java Script function on onClick ( button ) in JSP?

javascriptjsp

提问by Mad-D

I would like to trigger the js function onClick from button. for some reason i am facing Function not defined.

我想从按钮触发 js 函数 onClick 。出于某种原因,我面临未定义的功能。

Need to call this in JSP

需要在 JSP 中调用

// doUpdate function details
boolean doUpdate = request.getParameter("update")!=null;
String stateButton = request.getParameter("update");

if (doUpdate && catalogID != null && companyID != 0) {
    if(catalogManager!=null) {
        boolean success = catalogManager.updateStatus(new Integer(catalogID).intValue(),user, stateButton);
        if((stateButton.equals("Active")) && success) { 
    %>          
        <span class="TitleLevel01"><font color=green>Catalog is Activated.</font></span>
    <%
        }
        if((stateButton.equals("Active")) && !success) {
    %>
        <span class="TitleLevel01"><font color=red>Cannot activate subcatalog with Inactive parent.</font></span>
    <%      
        }
        if(!stateButton.equals("Active")) {
    %>                  
            <span class="TitleLevel01"><font color=green>Catalog is Deactivated.</font></span>
    <%      
            }
        }
    }

from this Form (looks like this)

从这个表格(看起来像这样)

 <form name="maintain_catalog_frm" id="maintain_catalog_frm" >
    <input type=hidden name="PID" value="">
    <input type="submit" name="update" value="Inactive" onClick="return doUpdate(document.maintain_catalog_frm);" >
    </form>

采纳答案by Sid Malani

Do you have js in the jsp or have you included js file in your jsp?

你在jsp中有js还是在你的jsp中包含了js文件?

Include your script in in your jsp.

将您的脚本包含在您的 jsp 中。

It looks like you have a jsp not js to execute here.

看起来你有一个 jsp 而不是 js 在这里执行。

Is companyid and catalogue initialised properly?

companyid 和 catalog 是否正确初始化?

回答by r0ast3d

It means that the javascript is still not loaded.

这意味着 javascript 仍未加载。

It could be your cache, or you could be having some wrong path to the JS file. What is the path to the JS file , and has it been downloaded?

它可能是您的缓存,或者您可能有一些错误的 JS 文件路径。JS文件的路径是什么,有没有下载?