<table id="mingxi"></table>
<div id="div_chongzhi_shenqing" align="center">
<div style=" margin-top:50px">
充值金額:<input type="text" id="chongzhi_money_shenqing" />
<br />
<br />
<br />
<input type="button" id="queren_chongzhi_shenqing" value="充值" />
</div>
</div>
<script type="text/javascript">
$('#mingxi').datagrid({
url: '../mingxi.ashx',
columns: [
[
{ field: 'cbo_dingdan', checkbox: true },
{ field: 'ID', title: 'ID', hidden: true },
{ field: 'UserName', title: '經銷商' },
{ field: 'Times', title: '日期' },
{ field: 'Money', title: '金額' },
{ field: 'DingDanhao', title: '淘寶訂單號' },
{ field: 'Chongzhiliyou', title: '來源' },
{ field: 'Zhuangtai', title: '狀態',
formatter: function (value, row, index) {
var a = "";
if (row.Zhuangtai == 0) {
a = "<span>等待充值</span>";
//s = "<a href='javascript:void(0)' onclick=chongzhi(" + index + ")>充值</a>";
}
else {
a = "<span>充值成功</span>";
}
return a;
}
},
{ field: 'caozuo', title: '操作',
formatter: function (value, row, index) {
var b = "";
if (row.Zhuangtai == 1) {
b = "<span>已充值</span>";
}
else {
b = "<a href='javascript:void(0)' onclick=chongzhi_shenqing(" + index + ")>充值</a>";
}
return b;
}
}
]
],
method: 'post',
rownumbers: true,
idField: 'ID',
pagination: true
})
$('#div_chongzhi_shenqing').dialog({
title: '充值',
width: 400,
height: 200,
closed: true,
cache: false,
onClose: function () {
$('#chongzhi_money_shenqing').val("");
},
modal: true
});
var selected;
function chongzhi_shenqing(index) {
$('#mingxi').datagrid('selectRow', index);
selected = $('#mingxi').datagrid('getSelected');
//alert(selected.UserName);
$('#div_chongzhi_shenqing').dialog('open');
}
</script>
<script type="text/javascript">
$(function () {
$('#queren_chongzhi_shenqing').click(function () {
//var selected = $('#mingxi').datagrid('getSelected');
//alert(selected.UserName);
alert("1");
$.ajax({
url: 'chongzhi.ashx',
type: 'post',
data: { 'id': selected.ID, 'Money': $('#chongzhi_money_shenqing').val(), 'user': selected.UserName },
success: function (msg) {
if (msg == "ok") {
alert("充值成功");
$('#mingxi').datagrid('reload');
}
if (msg == "null") {
alert("沒有要充值得記錄,請刷新重試");
}
if (msg == "error") {
alert("充值失敗,請重新嘗試");
}
if (msg == "small") {
alert("充值失敗,總充值金額不能小於0");
}
$('#chongzhi_money_shenqing').val("");
$('#div_chongzhi_shenqing').dialog('close');
}
})
})
})
</script>
我點擊充值,成功後,下一次充值,就會充值兩次,成功後,充值第三次,就會充值三次,為什麼啊。。。。
應該是你每次加載都綁定一次點擊事件的原因,你試試綁定充值點擊事件之前unbind解綁一下