1.
<table class="table"> <thead>
<tr>
<!-- <th>id</th> -->
<th>产品编号</th>
<th>产品图标</th>
<th>产品名称</th>
<th>产品介绍</th>
<th>产品标志</th>
<th>产品链接</th>
<th>今最大进入数</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach($row as $k => $val){ ?>
<tr>
<!-- <th><?php echo $val['id'];?></th> -->
<th><?php echo $val['product_id'];?></th>
<!-- <th><img src=<?php echo $val['product_img'];?> /></th> -->
<th><?php echo $val['product_img'];?></th>
<th><?php echo $val['product_title'];?></th>
<th><?php echo $val['product_introduce'];?></th>
<th><?php echo $val['product_remark'];?></th>
<th><?php echo $val['product_link'];?></th>
<th><?php echo $val['maxJoinNum'];?></th>
<th>
<a onclick="showAdd()">新增</a>|
<a onclick="change(<?php echo $val['product_id'];?>)">修改</a>|
<a onclick="Deourproduct(<?php echo $val['id']?>)">删除</a>
</th>
</tr>
<?php } ?>
</tbody>
</table>
2. <div id="changeour" class="add" >
<div class="addtop">修改产品</div>
<div class="addform">
今日最大数量:<input type="text" id="maxJoinNum" name="maxJoinNum"><br>
<input type="hidden" name="yincangID" id="yincangID" value="">
<button class="addbtn" onclick="changeour()">确定</button>
<!-- <button class="addbtn" style="margin-left:130px;" type="reset" value="重置">重置</button> -->
<button class="addbtn" style="margin-left:130px;" onclick="javascript:history.go(-1);location.reload() ">取消</button>
</div>
</div>
3. function change(ID){
document.getElementById('changeour').style.display = "block";
document.getElementById('yincangID').value=ID;
}
function changeour() {
var ID=document.getElementById('yincangID').value;
console.log('ID是'+ID);
var maxJoinNum=document.getElementById('maxJoinNum').value;
if(confirm("你确认修改吗")){
$.ajax({
//提交数据的类型 POST GET
type:"POST",
//提交的网址
url:"../Change/Changeour",
//提交的数据
data:{"product_id":ID,
"maxJoinNum":maxJoinNum,
},
//返回数据的格式
datatype: "json",
//成功返回之后调用的函数
success: function(data){
console.log(data);
if(data==1){
alert("修改成功 ");
window.location.reload();
}
},
//调用出错执行的函数
error:function(XMLHttpRequest, textStatus, errorThrown){
//请求出错处理
//alert("查看异常 "+errorThrown);
}
});
}else
return true; //单击取消,弹出框取消,页面不动
}
4. class Change extends Controller
{
public function Changeour(){
if(isset($_POST['product_id'])){
$id = $_POST['product_id'];
$maxjionnum = $_POST['maxJoinNum'];
$res = Db::connect('db_con3')->name('product_info')->where('product_id', $id)->update(['maxJoinNum' =>$maxjionnum ]);
return 1;
}
}
}
|