不调用javascript函数

不调用javascript函数,java,javascript,html,jsp,struts,Java,Javascript,Html,Jsp,Struts,在下面提到的代码中,当我点击“拼写检查”按钮时,它不会调用javascript函数。正在寻找您的积极响应。 多谢各位 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">

在下面提到的代码中,当我点击“拼写检查”按钮时,它不会调用javascript函数。正在寻找您的积极响应。 多谢各位

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html
    xmlns="http://www.w3.org/1999/xhtml">

    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib
    uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <%@ taglib
    uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%> <%@ taglib
    uri="/WEB-INF/struts-logic.tld" prefix="logic"%>

<head>Welcome To struts Application.

<title>Struts</title>

<script language="javascript">

    function input(){       alert("Insie input function)
          var abs = '<%=request.getContextPath()%>/index.do
            System.out.println("Path"+abs);
            alert(abs);   
          document.AccomodationForm.action=abs;
          document.AccomodationForm.submit();   }

</script> </head>

 <body>

    <html:form  method="post" action="/index"> <html:text
    property="username"></html:text> <html:password
    property="password"></html:password> <html:button  value="Spellcheck" 
    property="button" onclick="javascript:input()"></html:button>
    <html:link page="/index.do">Test the Action</html:link> </html:form>


    </body>


    </html>

欢迎使用struts应用程序。
支柱
函数输入(){alert(“Insie输入函数”)
var abs='/index.do
系统输出打印项次(“路径”+abs);
警报(abs);
document.acomodationform.action=abs;
document.acomodationForm.submit();}
测试动作
看看我在浏览器上看到的源代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">







<head>Welcome To struts Application.

<title>Struts</title>

<script language="javascript"> 

    function input(){
        alert('Insie input function');
          var abs = '/MyWork/index.do
            alert(abs);

          document.AccomodationForm.action=abs;
          document.AccomodationForm.submit();
    }

</script>
</head>


<body>

<form name="indexform" method="post" action="/MyWork/index.do;jsessionid=43C03A85FEBE58F375D2165C3E631111">
<input type="text" name="username" value="">
<input type="password" name="password" value="">
<input type="button" name="button" value="antriksh" onclick="input()">
<a href="/MyWork/index.do;jsessionid=43C03A85FEBE58F375D2165C3E631111">Test the Action</a>
</form>


</body>


</html>

欢迎使用struts应用程序。
支柱
函数输入(){
警报(“Insie输入功能”);
var abs='/MyWork/index.do
警报(abs);
document.acomodationform.action=abs;
document.acomodationform.submit();
}

问题是它正在按钮中插入名称属性。我不知道为什么?您身边的朋友有任何输入。

onclick
不带URL,因此
javascript:
部分是无关的。杀死它。

为什么javascript函数包含javacode
System.out.println(“Path”+abs)
,并且您的javascript代码中存在一些错误,请参见以下内容:

 function input(){      
      alert("Insie input function");
      var abs = '<%=request.getContextPath()%>/index.do';
       alert(abs);   
      document.AccomodationForm.action=abs;
      document.AccomodationForm.submit();   
 }
函数输入(){
警报(“Insie输入功能”);
var abs='/index.do';
警报(abs);
document.acomodationform.action=abs;
document.acomodationform.submit();
}

我想修正打字错误可以让你的代码正常工作:

function input() {
    //close the String message for the alert function
    alert("Insie input function)";
    //solve the scriptlet problem
    var abs = '<%=request.getContextPath()%>' + '/index.do'
    //THIS IS JAVA CODE, NOT JAVASCRIPT => System.out.println("Path"+abs);
    alert(abs);
    document.forms[0].action=abs;
    document.forms[0].submit();

关闭单引号将解决问题

var abs=''+'/index.do';


如果您使用Firefox,我们将使用错误控制台(Ctrl+Shift+J)发现脚本错误

如果这是您的真实代码,那么它在
输入
函数中有一些输入错误:在第一次
警报
调用结束时使用分号,关闭scriptlet的
(事实上,scriptlet现在是一种糟糕的做法)。很抱歉,我已经更正了输入错误。但它仍然没有调用输入函数。@ANk:没有。它不起作用。我发布了一个可能解决您的JavaScript问题的答案。我刚刚制作了一个JSFIDLE来测试这个问题,发现它可以工作。我删除了JavaScript:部分并更正了一些输入错误,但它仍然没有调用输入函数@Jason:有一些输入错误,我已经更正了。代码u发布的其他内容也有错误,请在单列中发出警告:)@Antriksh现在有什么错误,你能在控制台或firebug中看到错误吗?@Jason:我已经发布了源代码。我不知道按钮标签中的name属性在哪里。网页错误详细信息:u指定的字符串常量行:18字符:35代码:0 URI:消息:对象预期行:34字符:1代码:0 URI: