0

在下面提到的代码中,当我单击“拼写检查”按钮时。它没有调用 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>

看看我在浏览器上看到的源代码

<!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>

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

4

4 回答 4

0

onclick不采用 URL,因此该javascript:部分是无关的。杀了它。

于 2013-02-20T07:20:58.910 回答
0

为什么您的 javascript 函数包含java代码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();   
 }
于 2013-02-20T07:23:28.203 回答
0

我想修复错别字可以使您的代码正常工作:

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();

}

并按照其他答案的建议,删除标签组件javascript:中的:<html:button

<html:button  value="Spellcheck"
    property="button" onclick="input()"></html:button>
于 2013-02-20T07:32:05.227 回答
0

关闭单引号即可解决问题

var abs = '<%=request.getContextPath()%>' + '/index.do';

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

于 2013-08-22T05:13:57.340 回答