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;
}
}
}
|