jquery自定义属性,解决List中按钮传值问题

来源:互联网 发布:淘宝上可靠的种子店 编辑:程序博客网 时间:2024/06/09 15:42

      用JQuery对前台代码进行规范,遇到一些问题。对集合数据进行遍历时,操作单条数据的增、删、改、查,需要传递一些参数进行后台的处理。
      本人在项目中用标签的自定义属性传值,然后jquery使用attr便可访问到,这样可以减少javascript脚本中代码和数据的耦合


下面是例子代码,仅供参考:
<script type="text/javascript">
  $(document).ready(function(){
   //ajax删除
   $(".btn_delete").click(function(){
    ret = window.confirm('${texts['dtaq.common.delete.msg']}');
    if(ret){
      $.ajax({
         type: "POST",
        url: 'sysCodeRuleitemAction.do?method=delete'+'&id='+$(this).attr("paramId")+'&ruleid='+$(this).attr("paramRuleid"),
         success: function(msg){
         $('#childbody').html(msg);
         }
     });
    }
   });
   //
  });
</script>
<fieldset>
  <legend>
   [***********]
  </legend>
<table class="defTable" >
 <thead>
  <tr >
   <th width="5%" >序号</th>
    <th width="25%">*****</th>
    <th width="10%" >*****</th>
    <th width="10%" >*****</th>
    <th width="25%" >*****</th>
  </tr>
  </thead>
  <c:forEach items="${sysCodeRuleitems}" varStatus="index" var="sysCodeRuleitem">
   <tr class="tr07">
    <td>${index.count}</td>
    <td>${sysCodeRuleitem.ruletype}&nbsp;</td>
    <td>${sysCodeRuleitem.rulecontent}&nbsp;</td>
    <td>${sysCodeRuleitem.orderno}&nbsp;</td>
    <td>
     <div >
            <input type="button" class="button1 btn_edit"  value="${texts['button.edit']}"
            paramId="${sysCodeRuleitem.id}" paramRuleid="${param.ruleid}"/>
      <input type="button" class="button1 btn_delete" value="${texts['button.delete']}"
       paramId="${sysCodeRuleitem.id}" paramRuleid="${param.ruleid}"/>   
     </div>
    </td>
   </tr>
  </c:forEach>
 </table>
</fieldset>

原创粉丝点击