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

タイプミスを修正すると、コードが機能するようになると思います。

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 に答える
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 に答える