<table class="table table-hover table-bordered table-striped dataTable"> <!--表头--> <thead> <tr role="row"> <th class="sorting text-center" tabindex="0" rowspan="1" colspan="1"> ID </th> <th class="sorting text-center" tabindex="0" rowspan="1" colspan="1"> 昵称 </th> <th class="sorting text-center" tabindex="0" rowspan="1" colspan="1"> 所属游戏 </th> <th class="sorting text-center" tabindex="0" rowspan="1" colspan="1"> 押注规则 </th> <th class="sorting text-center" tabindex="0" rowspan="1" colspan="1"> 创建时间 </th> <th class="sorting text-center" tabindex="0" rowspan="1" colspan="1"> 操作 </th> <th class="sorting text-center" tabindex="0" rowspan="1" colspan="1"> 修改昵称 </th> </tr> </thead> <!--表体--> <tbody> <% for(let i = 0; i < list.length ; i++){ %> <% var item = list[i]; %> <tr role="row"> <td class="text-nowrap text-center"><%= item.id %></td> <td class="text-nowrap nick-name"> <div class="avatar-image pull-left" style="background-image: url(‘/resources/photo/<%= item.avatar %>‘);width: 40px;height: 40px;margin-right: 4px;"></div> <span style="line-height: 40px"><%= item.nickname %></span> </td> <td class="text-nowrap text-center"><%= item.game_name %></td> <td class="text-nowrap text-center"><%- item.actions.join(‘<br/>‘) %></td> <td class="text-nowrap text-center"><%= dateformat(item.createtime, ‘yyyy/mm/dd HH:MM:ss‘) %></td> <td class="text-nowarp text-center"> <a href="javascript:;" class="btn btn-sm btn-info btn-edit" data=‘<%- JSON.stringify(item) %>‘ title="编辑">编辑</a> <a href="javascript:;" class="btn btn-sm btn-danger btn-del" data-id=‘<%= item.id %>‘ title="删除">删除</a> </td> <td class="text-nowarp text-center" data-id="<%= item.id %>"> <a href="#" class="btn btn-default btn-sm btn-change" data-name="<%= item.nickname %>" data-toggle="modal" data-target="#nickNameModal">更改昵称</a> </td> </tr> <% } %> </tbody></table> <script type="text/javascript">
$(document).ready(function () {
var name; var id; var oldNickName = $(‘#oldNickName‘); var editData; //更改昵称 $(‘tbody‘).on(‘click‘,‘.btn-change‘,function () { var $this = $(this); id = $this.parent().data(‘id‘);//获取父级td的 name = $this.data(‘name‘);//获取btn-change当前层级的 oldNickName.text(name);//赋值给id为oldNickName的 })
})
<script>
原文地址:https://www.cnblogs.com/sunKAMI/p/10914181.html
时间: 2024-10-17 05:18:13