我正在发布帖子。当我使用按钮增加总值时,则显示值,但是当我单击请求按钮时,所有发布都会更新,但余额不会更新。我检查数据库插入“你有转移$ [对象对象]帐户余额”。请帮助解决问题并帮助我完善。
$(function(){
var theTotal = 10;
$('.add').click(function(){
theTotal = Number(theTotal) + Number($(this).val());
$('.total').text(theTotal.toFixed(2));
});
$('.sub1').click(function(){
if(theTotal > 10) {
theTotal = Number(theTotal) - Number($(this).val());
};
$('.total').text(theTotal.toFixed(2));
});
$('.sub2').click(function(){
if(theTotal > 10) {
theTotal = Number(theTotal) - Number($(this).val());
};
$('.total').text(theTotal.toFixed(2));
});
$('.sub3').click(function(){
if(theTotal > 10) {
theTotal = Number(theTotal) - Number($(this).val());
};
$('.total').text(theTotal.toFixed(2));
});
var af = $('.total').text(theTotal.toFixed(2));
$('#request').click(function(){
$.ajax({
type:'POST',
url:window.location.protocol+'//'+window.location.host+'/?add=fund',
data:'qun='+af,
cache:false,
beforeSend:function(){
$('html *').addClass('op-progress');
}, success:function(html){
$('html *').removeClass('op-progress');
document.location.href=_url+'/?add=fund';
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<table style="margin-bottom:15px;">
<tr>
<td>
<button class="sub3 p_btn" value="10"><<<</button>
<button class="sub2 p_btn" value="10"><<</button>
<button class="sub1 p_btn" value="10"><</button>
</td>
<td>
<span class="f_mb_dol">$</span>
<span class="total f_mb_text"></span>
<div class="f_mb_dol">usd</div>
</td>
<td>
<button class="add p_btn" value="10">></button>
<button class="add p_btn" value="10">>></button>
<button class="add p_btn" value="10">>>></button>
</td>
</tr>
</table>
<table>
<tr>
<td><button id="request" class="btn_enable" style="cursor:pointer;"><span>Transfer balance</span></button></td>
</tr>
</table>
答案 0 :(得分:0)
您正在发送数据中的整个元素。 我相信你只需要发送数据。你在线上做什么 var af = $('。total')。text(theTotal.toFixed(2)); 你是设置该元素的值并将元素分配给变量。
记住 .text(某事物)设置值
.text()获取值
$(function(){
var af;
var theTotal = 10;
$('.add').click(function(){
theTotal = Number(theTotal) + Number($(this).val());
$('.total').text(theTotal.toFixed(2));
});
$('.sub1').click(function(){
if(theTotal > 10) {
theTotal = Number(theTotal) - Number($(this).val());
}
$('.total').text(theTotal.toFixed(2));
});
$('.sub2').click(function(){
if(theTotal > 10) {
theTotal = Number(theTotal) - Number($(this).val());
}
$('.total').text(theTotal.toFixed(2));
});
$('.sub3').click(function(){
if(theTotal > 10) {
theTotal = Number(theTotal) - Number($(this).val());
}
$('.total').text(theTotal.toFixed(2));
});
$('.total').text(theTotal.toFixed(2));
$('#request').click(function(){
af = $('.total').text();
console.log(af);
$.ajax({
type:'POST',
url:window.location.protocol+'//'+window.location.host+'/?add=fund',
data:'qun='+af,
cache:false,
beforeSend:function(){
$('html *').addClass('op-progress');
}, success:function(html){
$('html *').removeClass('op-progress');
document.location.href=_url+'/?add=fund';
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<table style="margin-bottom:15px;">
<tr>
<td>
<button class="sub3 p_btn" value="10"><<<</button>
<button class="sub2 p_btn" value="10"><<</button>
<button class="sub1 p_btn" value="10"><</button>
</td>
<td>
<span class="f_mb_dol">$</span>
<span class="total f_mb_text"></span>
<div class="f_mb_dol">usd</div>
</td>
<td>
<button class="add p_btn" value="10">></button>
<button class="add p_btn" value="10">>></button>
<button class="add p_btn" value="10">>>></button>
</td>
</tr>
</table>
<table>
<tr>
<td><button id="request" class="btn_enable" style="cursor:pointer;"><span>Transfer balance</span></button></td>
</tr>
</table>