struts 1.3 html标签库支持jquery吗?

时间:2013-09-16 15:40:19

标签: jquery ajax struts-1

我编写了一个简单的jsp代码,我在使用struts 1.3 html标记库标记。我想在按钮的click事件上对struts动作类进行ajax调用。为了使jQuery需要元素的id或标签名称(这里是按钮的id),因为我将在JSP中使用多个按钮,使用标记名称是不可能的。但是html标签库的元素没有属性作为“id”。请给我一个解决这个问题的方法?

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>


$(document).ready(function(){
  $("#action").click(function(){
      alert("inside function");
      var dataToBeSent = $("form").serialize();

      $.post("http://localhost:8013/MyProject1/details.do", dataToBeSent, function(data, textStatus) {

              alert(data.income);
              alert(data.taxReturn);
              alert(textStatus);
              $("#income").val(data.income);
              $("#taxReturn").val(data.taxReturn);

        }, "json");

      });

   });


</script>
</head>
<body>

<table>
<tr><td>
<html:form action="details.do">

SSN : <html:text  property="numberSSN" />  <br/>
YEAR : <html:text property="year" /> <br/>
INCOME: <html:text  property="income" value=""/><br/>
TAX: <html:text property="taxReturn" value=""/><br/> <br/>


<html:button  property="action"  >TestClickEvent </html:button>
<html:reset></html:reset>
</html:form>

<div id="details1">
</div>
</td>
</tr? 

</body>
</html>

这里我要添加渲染的HTML代码

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>


$(document).ready(function(){
  $("#htmlFindButton").click(function(){
      alert("inside function");
      var dataToBeSent = $("form").serialize();

      $.post("http://localhost:8013/MyProject1/details.do?action=\"find\" ", dataToBeSent, function(data, textStatus) {

              alert(data.income);
              alert(data.taxReturn);
              alert(textStatus);
              $("#income").val(data.income);
              $("#taxReturn").val(data.taxReturn);

        }, "json");

      });

   });


</script>
</head>
<body>

<table>
<tr><td>
<form name="detailsForm" method="post" action="/MyProject1/details.do;jsessionid=A42FCDD6D26ACC6631384375C69D2743">

SSN : <input type="text" name="numberSSN" value="0">  <br/>
YEAR : <input type="text" name="year" value=""> <br/>
INCOME: <input type="text" name="income" value=""><br/>
TAX: <input type="text" name="taxReturn" value=""><br/> <br/>

<span id="htmlFindButton" >
<input type="button" name="action" value="TestClickEvent"> </span>
<input type="reset" value="Reset">
</form>

<div id="details1">
</div>
</td>
</tr>


</table>

<p>
   <a href="/MyProject1/Welcome.do;jsessionid=A42FCDD6D26ACC6631384375C69D2743">Click me to access to JSP Welcome page</a>
</p> 

</body>
</html>

这里我添加完整的(在我提交表单到LookUpDispatchAction时,在span中有两个按钮)呈现的html代码

0 个答案:

没有答案