1.效果
2.html代码
<form method="post" action="a.php(自己改)" name="theFormx">
<table cellspacing="3" border="0" cellpadding="1" width="100%">
{foreach from=$show_data item=vv key=kk}
<tr>
{foreach from=$vv item=vv2 key=kk2}
<td class="label" >{$vv2.name}</td>
<td width="6%"><input type="text" class="" name="account_name" data-oldfee="{$vv2.show_taxes_fee}" data-id="{$vv2.bid}" style="width:100%;" maxlength="100" value="{$vv2.show_taxes_fee}" /></td>
{/foreach}
</tr>
{/foreach}
</table>
</form>
或者
<tr>
<td class="label_td" >xxxx </td>
<td>
<input type="text" class="form-control-ele edit_fee_class" name="late_fee" data-name2="late_fee" data-oldfee="{$row.late_fee}" data-id="1" style="width:5%;" maxlength="100" value="{$row.late_fee}" />
</td>
</tr>
3.js
$('#id(自己改)').on('blur','.class文件名(自己改)',function(e){
if (e.target.value != e.target.dataset.oldfee){
let data = {bid:e.target.dataset.id,fee:e.target.value,act:'ajax_edit_fee(自己改)',}
$.post('a.php(自己改)',data,function (res){
if (res.status){
e.target.dataset.value = e.target.value
}else{
layer.msg(res.msg,{anim: 6,time:1000})
}
})
}
})
例子:
$('#tabbody-div').on('blur','.edit_fee_class',function(e){
if (e.target.value != e.target.dataset.oldfee){
let data = {bid:e.target.dataset.id,fee:e.target.value,name:e.target.dataset.name2,act:'ajax_edit_fee',}
$.post('xxxxx.php',data,function (res){
if (res.status){
e.target.dataset.value = e.target.value
}else{
layer.msg(res.msg,{anim: 6,time:1000})
}
})
}
})
4.引入js文件
jq.js一定要引入
layer.js文件,也可以不引入
5.核心思路
dataset就是html的data的数组,就是data-xx的值
如bid:e.target.dataset.id就是data-id=“”里面的值
6.php提交
if ($_REQUEST['act'] == 'ajax_edit_fee')
{
$id = intval($_REQUEST['bid']);
$value = $_REQUEST['fee'];
$name = trim($_REQUEST['name']);
if (empty($id)){
json(0,'id不存在');
}
if (empty($value)) {
json(0,'未填写值');
}
if (empty($name)){
json(0,'字段名空');
}
$update = [];
$update[$name] = $value;
$res = db_work_attendance_fee_set::update($id,$update);
if(!$res)
{
json(0,'修改失败');
}
/* 记日志 */
add_system_log('xxxx', 'edit',$id,'xxxxx');
json(1,'修改成功');
}