源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

JQuery使用$.ajax和checkbox实现下次不在通知功能

  • 时间:2022-05-28 08:14 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:JQuery使用$.ajax和checkbox实现下次不在通知功能
XXX平台要实现一个功能,公告弹出页面上使用复选框设置不再通知此类公告。   原理:<input type="checkbox" id="isSelect" name="isSelect" value="10" onclick="javascript:noTips();"/>,checkbox选中后提交表单,那么struts2的Action中isSelect就为'10',不选中提交表单isSelect为null。   [b]1.jsp页面[/b]
<form id="form1"> 
<div class="jf_tanchu"> 
  <div class="jf_tanchutit">${ bussinessNotice.noticeTitle}</div> 
  <div class="jf_tanchubox"> 
    <div class="jf_tanchubox_right"> 
    公告类型:<v:dcolor code="${ bussinessNotice.noticeType}"/>     
    发布时间:<fmt:formatDate value="${ bussinessNotice.createDate}" pattern="yyyy-MM-dd"/> 
    </div> 
    ${bussinessNotice.noticeInfo} 
  </div> 
</div> 
<s:if test="bussinessNotice.noticeType=='25'||bussinessNotice.noticeType=='63'||bussinessNotice.noticeType=='64'"> 
<div> 
  <input type="hidden" name="noticeType" value="${bussinessNotice.noticeType}"/> 
  <input type="checkbox" id="isSelect" name="isSelect" value="${bussinessNotice.noticeType}" onclick="javascript:noTips();"/> 
  <label for="isSelect">不再通知此类公告</label> 
</div> 
</s:if> 
</form> 

[b] 2.js代码[/b]
 function noTips(){ 
  var formParam = $("#form1").serialize();//序列化表格内容为字符串 
  $.ajax({ 
    type:'post',   
    url:'Notice_noTipsNotice', 
    data:formParam, 
    cache:false, 
    dataType:'json', 
    success:function(data){ 
    } 
  }); 
} 
 
[b] 3.NoticeAction代码[/b]
/** 
 * checkbox不提示公告,需要修改TBussinessSet中的屏蔽状态,ajax异步请求 
 */ 
public void noTipsNotice(){ 
  try { 
    PrintWriter out = this.getResponse().getWriter(); 
     
    bussinessSet = BussinessSetService.queryById(getUserId()); 
    String state = ""; 
    if(isSelect==null){//noticeType==null没有选中checkbox 
      state = "11"; 
    } 
    else{ 
      state = "10"; 
    } 
    if("25".equals(noticeType)){ 
      bussinessSet.setSaleBack(state); 
    } 
    else if("63".equals(noticeType)){ 
      bussinessSet.setRemittanceBank(state); 
    } 
    else if("64".equals(noticeType)){ 
      bussinessSet.setRemittanceOnline(state); 
    } 
    BussinessSetService.update(bussinessSet); 
     
    out.print(""); 
  } catch (Exception e) { 
    log.error(e.fillInStackTrace()); 
  } 
} 
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部