jq 多个《button》 点击事件(含 ajax ,action), 功能版

来源:互联网 发布:sas数据分析大赛题目 编辑:程序博客网 时间:2024/05/25 21:36
<%@page import="com.baishiji.www.bean.SMSbeans"%><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@taglib  prefix="s"  uri="/struts-tags"  %><%String serverName= request.getContextPath();;//项目名 %><!DOCTYPE html><html>  <head>           <title>短信群发列表页</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">-->    <link rel="stylesheet" href="<%=serverName%>/css/jHsDate.css" /><style>.body{       margin:0;       padding:0;        font-size:30px;        font-weight:bold;        } .parent{       text-align:center;        line-height:200px;    }  #mohusearch{float:right;margin-top:10px;margin-right:100px;}#main {margin-top:100px;margin-left:2px;margin-right:2px; align:center; border:1px solid green;   }#tel{    position:absolute;left:10px;top:60px;       width:400px;      height:500px;        }table {border-collapse:collapse;border-spacing:0;border:1px solid #c0c0c0;width:auto;}th,td {border:1px solid #d0d0d0;color:#404060;padding:10px;}th {background-color:#09c;font:bold 16px "微软雅黑";color:#fff;}td {font:14px "微软雅黑";</style>  </head>  <script type="text/javascript" src="<%=serverName%>/js/jquery-1.10.2.js"></script>   <body>  <div><jsp:include page="/navigationbar/navigation.jsp" flush="true" /></div>  <div class="panel"></div>    <div  id="main">      <table><thead><tr><th width="100">序号</th><th width="100">MsgContext</th><th width="200">Iswho</th><th width="100">设置</th></tr></thead><s:iterator id="msgTemplet" value="msgtempletlist" status="st"><tr><td>${st.index+1}</td><td id="msgTd${msgTemplet.msgId}" style="display:none">${msgTemplet.msgId}</td><td >${msgTemplet.msgContext}</td><td>${msgTemplet.iswho}</td><td><button  uid="but${msgTemplet.msgId}" type="button"  >设置默认</button></td></tr></s:iterator>              </table>         </div>   </body><script type="text/javascript">$(document).ready(function(){ $(document).on("click", "button", function () { var uid = $(this)[0].getAttribute('uid');//拆分转换为  msgId ;var msid=uid.substring("3"); var user = { // jHsDateStart:$("#datetimeStart").val(),  msgId:msid  };        $.ajax({            url:'SetMsgTempletAction.action',            data:user,            type:'post',            dataType:'text',             contentType:'application/x-www-form-urlencoded; charset=utf-8',            success:function(msg){              $("#main").empty();    $("#main").html(msg);            }                     });        });        });</script></html>


功能简介  点击 对应的按钮  直接 ajax  返回来来    后台 查询 修改后的数据库 中的数据


package com.baishiji.action.msgtemplet;import java.io.IOException;import java.io.PrintWriter;import java.util.List;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.ServletActionContext;import com.baishiji.bean.CaseInfo;import com.baishiji.bean.MsgTemplet;import com.baishiji.dao.CaseInfoDao;import com.baishiji.dao.MsgTempletDao;import com.opensymphony.xwork2.ActionSupport;public class SetMsgTempletAction extends ActionSupport {String  msgId;public void setWho() throws IOException{MsgTempletDao  mtd = new  MsgTempletDao();//查询   之前的那个默认 字段 清空mtd.searchTemplet("1");//对传来的 数据 进行 修改mtd.modifyIswho(Integer.parseInt(msgId) ,"1");respones(mtd);}private void respones(MsgTempletDao  mtd) throws IOException {//遍历  list 重新  刷新List<MsgTemplet>list= mtd.search();  HttpServletResponse response = ServletActionContext.getResponse();        response.setContentType("text/html;charset=UTF-8");         response.setCharacterEncoding("UTF-8");        PrintWriter writer = response.getWriter();          StringBuffer  sb = new  StringBuffer();sb.append("<table>");sb.append("<thead>");sb.append("<tr>");sb.append("<th width='100'>序号</th>");sb.append("<th width='100'>MsgContext</th>");sb.append("<th width='200'>Iswho</th>");sb.append("<th width='100'>设置</th>");sb.append("</tr>");sb.append("</thead>");sb.append("<tr>");for (int i = 0; i < list.size(); i++) {           int  msgId =list.get(i).getMsgId();sb.append("<td id=>" + (i + 1) + "</td>");//sb.append("<s:hidden id ='msgId' value='%{msgId}'></s:hidden>");sb.append("<td id='msgTd"+msgId+"'style='display:none'>"+msgId+"</td>");sb.append("<td >" + list.get(i).getMsgContext() + "</td>");sb.append("<td>" + list.get(i).getIswho() + "</td>");sb.append("<td><button  uid='but"+list.get(i).getMsgId()+"' type='button'  >设置默认</button></td>");sb.append("</tr>");} sb.append("</table>"); writer.print(sb);        writer.flush();        writer.close();}public String getMsgId() {return msgId;}public void setMsgId(String msgId) {this.msgId = msgId;}}


原创粉丝点击