如何从JSP中的按钮调用函数 [英] How to call a function from a button click in JSP

查看:1040
本文介绍了如何从JSP中的按钮调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下功能:

<script>
function assign()
{
String val="";
String val = document.form1.text1.value;
System.out.println(val);
}
</script>

我正在尝试按钮中的功能,如下所示:

i am trying to call the function in the button click as shown below:

  <button type="button" onclick="assign()">Display</button> 

当我点击按钮没有任何反应。我想要在控制台上打印文本框中的字符串值。请帮助

When i click on the button nothing happens. I want the string value in the text box to be printed on the console.Please help

推荐答案

首先,如果你是尝试在按钮上点击JavaScript,然后您的语法错误。看到,你正在将Java与脚本标签中的JavaScript(代码)混合,这是无效的。

First of all, if you are trying to call JavaScript on button click, then your syntax is wrong. See, you are mixing Java with JavaScript (code) in script tag, that is invalid.

使用如下:

<script>
    function assign() {
        var val = "";
        val = document.form1.text1.value;
        alert(val); or console.log(val);
    }
</script>

 <button type="button" onclick="javascript:assign();">Display</button> 

这篇关于如何从JSP中的按钮调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆